Class: Mattock::Configurable::FieldProcessor
- Inherits:
-
Object
- Object
- Mattock::Configurable::FieldProcessor
show all
- Defined in:
- lib/mattock/configurable/field-processor.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of FieldProcessor.
4
5
6
7
|
# File 'lib/mattock/configurable/field-processor.rb', line 4
def initialize(source)
@source = source
@field_names = filter(source.class.field_names)
end
|
Instance Attribute Details
#field_names ⇒ Object
Returns the value of attribute field_names.
8
9
10
|
# File 'lib/mattock/configurable/field-processor.rb', line 8
def field_names
@field_names
end
|
#source ⇒ Object
Returns the value of attribute source.
9
10
11
|
# File 'lib/mattock/configurable/field-processor.rb', line 9
def source
@source
end
|
Instance Method Details
#filter(field_names) ⇒ Object
15
16
17
18
19
|
# File 'lib/mattock/configurable/field-processor.rb', line 15
def filter(field_names)
field_names.find_all do |name|
source.class.field_metadata(name).is?(filter_attribute)
end
end
|
#filter_attribute ⇒ Object
11
12
13
|
# File 'lib/mattock/configurable/field-processor.rb', line 11
def filter_attribute
raise NotImplementedError
end
|
#to(target) ⇒ Object
25
26
27
28
29
30
31
|
# File 'lib/mattock/configurable/field-processor.rb', line 25
def to(target)
field_names.each do |name|
field = source.class.field_metadata(name)
next unless target.respond_to?(field.writer_method)
target.__send__(field.writer_method, value(field))
end
end
|
#value(field) ⇒ Object
21
22
23
|
# File 'lib/mattock/configurable/field-processor.rb', line 21
def value(field)
source.__send__(field.reader_method)
end
|