Class: Flatter::Mapping
- Inherits:
-
Object
- Object
- Flatter::Mapping
- Extended by:
- ActiveSupport::Autoload
- Defined in:
- lib/flatter/mapping.rb
Defined Under Namespace
Modules: Scribe Classes: Factory
Instance Attribute Summary collapse
-
#mapper ⇒ Object
readonly
Returns the value of attribute mapper.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#target_attribute ⇒ Object
readonly
Returns the value of attribute target_attribute.
Instance Method Summary collapse
-
#initialize(mapper, name, target_attribute, **options) ⇒ Mapping
constructor
A new instance of Mapping.
- #read ⇒ Object
- #read! ⇒ Object
- #read_as_params ⇒ Object
- #write(value) ⇒ Object
- #write!(value) ⇒ Object
- #write_from_params(params) ⇒ Object
Constructor Details
#initialize(mapper, name, target_attribute, **options) ⇒ Mapping
Returns a new instance of Mapping.
12 13 14 15 16 17 |
# File 'lib/flatter/mapping.rb', line 12 def initialize(mapper, name, target_attribute, **) @mapper = mapper @name = name.to_s @target_attribute = target_attribute @options = end |
Instance Attribute Details
#mapper ⇒ Object (readonly)
Returns the value of attribute mapper.
8 9 10 |
# File 'lib/flatter/mapping.rb', line 8 def mapper @mapper end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/flatter/mapping.rb', line 8 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/flatter/mapping.rb', line 8 def @options end |
#target_attribute ⇒ Object (readonly)
Returns the value of attribute target_attribute.
8 9 10 |
# File 'lib/flatter/mapping.rb', line 8 def target_attribute @target_attribute end |
Instance Method Details
#read ⇒ Object
19 20 21 |
# File 'lib/flatter/mapping.rb', line 19 def read read! end |
#read! ⇒ Object
23 24 25 |
# File 'lib/flatter/mapping.rb', line 23 def read! target.public_send(target_attribute) end |
#read_as_params ⇒ Object
35 36 37 |
# File 'lib/flatter/mapping.rb', line 35 def read_as_params {name => read} end |
#write(value) ⇒ Object
27 28 29 |
# File 'lib/flatter/mapping.rb', line 27 def write(value) write!(value) end |
#write!(value) ⇒ Object
31 32 33 |
# File 'lib/flatter/mapping.rb', line 31 def write!(value) target.public_send("#{target_attribute}=", value) end |
#write_from_params(params) ⇒ Object
39 40 41 |
# File 'lib/flatter/mapping.rb', line 39 def write_from_params(params) write(params[name]) if params.key?(name) end |