142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/utils/filter.rb', line 142
def connect(resource, table_accessor)
connectors = @connectors
struct_fields = connectors.values.map(&:field_name)
connector_blocks = connectors.map do |method, c|
[method.to_sym, create_connector(c)]
end
entry_struct = Struct.new(*struct_fields.map(&:to_sym)) do
attr_accessor :__filter
def to_s
@__filter || super
end
end unless struct_fields.empty?
table = Class.new(Table) {
connector_blocks.each do |x|
define_method x[0], &x[1]
end
define_method :new_entry do |hashmap, filter = ''|
return entry_struct.new if hashmap.nil?
res = entry_struct.new(*struct_fields.map { |x| hashmap[x] })
res.__filter = filter
res
end
}
accessors = @accessors + @connectors.keys
accessors.each do |method_name|
resource.send(:define_method, method_name.to_sym) do |*args, &block|
filter = table.new(self, method(table_accessor).call, ' with')
filter.method(method_name.to_sym).call(*args, &block)
end
end
end
|