Class: TestAbstractions::Filler
- Inherits:
-
Object
- Object
- TestAbstractions::Filler
- Includes:
- Initializer
- Defined in:
- lib/test_abstractions/filler.rb
Class Method Summary collapse
- .build(data, form, mapping = nil) ⇒ Object
- .map(attribute_name, form) ⇒ Object
- .mapping(data, form) ⇒ Object
Instance Method Summary collapse
Class Method Details
.build(data, form, mapping = nil) ⇒ Object
8 9 10 11 12 |
# File 'lib/test_abstractions/filler.rb', line 8 def self.build(data, form, mapping=nil) mapping ||= self.mapping(data, form) instance = new data, form, mapping instance end |
.map(attribute_name, form) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/test_abstractions/filler.rb', line 23 def self.map(attribute_name, form) setter = "#{attribute_name}=" return nil unless form.respond_to? setter return attribute_name, attribute_name end |
.mapping(data, form) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/test_abstractions/filler.rb', line 14 def self.mapping(data, form) mapping = {} data.attribute_names.each do |attribute_name| data_attribute, form_attribute = map attribute_name, form mapping[data_attribute] = form_attribute if form_attribute end mapping end |
Instance Method Details
#! ⇒ Object
30 31 32 33 34 |
# File 'lib/test_abstractions/filler.rb', line 30 def ! mapping.each do |data_attribute, form_attribute| copy data_attribute, form_attribute end end |
#copy(data_attribute, form_attribute) ⇒ Object
36 37 38 39 40 |
# File 'lib/test_abstractions/filler.rb', line 36 def copy(data_attribute, form_attribute) value = data.attributes[data_attribute] form.send "#{form_attribute}=", value return value, data_attribute, form_attribute end |