/usr/lib/ruby/vendor_ruby/gir_ffi/builders/property_builder.rb is in ruby-gir-ffi 0.9.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | module GirFFI
module Builders
# Creates property getter and setter code for a given IPropertyInfo.
class PropertyBuilder
def initialize(property_info)
@info = property_info
end
def build
setup_getter
setup_setter if setting_allowed
end
def setup_getter
container_class.class_eval getter_def unless container_defines_getter_method?
end
def container_defines_getter_method?
container_info.find_instance_method getter_name
end
def setup_setter
container_class.class_eval setter_def
end
# TODO: Fix argument builders so converting_getter_def can always be used.
def getter_def
case type_info.tag
when :glist, :ghash
converting_getter_def
else
simple_getter_def
end
end
# TODO: Fix argument builders so converting_setter_def can always be used.
def setter_def
case type_info.flattened_tag
when :glist, :ghash, :strv
converting_setter_def
else
simple_setter_def
end
end
private
# TODO: Use a builder like MarshallingMethodBuilder
def converting_getter_def
capture = getter_builder.capture_variable_name
<<-CODE.reset_indentation
def #{getter_name}
#{capture} = get_property("#{property_name}")
#{getter_builder.post_conversion.join("\n")}
#{getter_builder.return_value_name}
end
CODE
end
def simple_getter_def
<<-CODE.reset_indentation
def #{getter_name}
get_property("#{property_name}")
end
CODE
end
def getter_builder
@getter_builder ||= ReturnValueBuilder.new(VariableNameGenerator.new,
argument_info)
end
def converting_setter_def
<<-CODE.reset_indentation
def #{setter_name} value
#{setter_builder.pre_conversion.join("\n")}
set_property("#{property_name}", #{setter_builder.call_argument_name})
end
CODE
end
def simple_setter_def
<<-CODE.reset_indentation
def #{setter_name} value
set_property("#{property_name}", value)
end
CODE
end
def setter_builder
@setter_builder ||= ArgumentBuilder.new(VariableNameGenerator.new,
argument_info)
end
def property_name
@info.name
end
def getter_name
@info.getter_name
end
def setter_name
@info.setter_name
end
def type_info
@type_info ||= @info.property_type
end
def argument_info
@argument_info ||= FieldArgumentInfo.new('value', type_info)
end
def container_class
@container_class ||= container_module.const_get(container_info.safe_name)
end
def container_module
@container_module ||= Object.const_get(container_info.safe_namespace)
end
def container_info
@container_info ||= @info.container
end
def setting_allowed
@info.writeable? && !@info.construct_only?
end
end
end
end
|