Module: Flatter::Mapper::Mapping
- Extended by:
- ActiveSupport::Concern
- Included in:
- Flatter::Mapper
- Defined in:
- lib/flatter/mapper/mapping.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #mapping(name) ⇒ Object
- #mapping_names ⇒ Object
- #mappings ⇒ Object
- #read ⇒ Object
- #writable_mapping_names ⇒ Object
- #write(params) ⇒ Object
Instance Method Details
#[](name) ⇒ Object
62 63 64 |
# File 'lib/flatter/mapper/mapping.rb', line 62 def [](name) mappings[name.to_s].try(:read) end |
#[]=(name, value) ⇒ Object
66 67 68 |
# File 'lib/flatter/mapper/mapping.rb', line 66 def []=(name, value) mappings[name.to_s].try(:write, value) end |
#mapping(name) ⇒ Object
70 71 72 |
# File 'lib/flatter/mapper/mapping.rb', line 70 def mapping(name) mappings[name.to_s] end |
#mapping_names ⇒ Object
54 55 56 |
# File 'lib/flatter/mapper/mapping.rb', line 54 def mapping_names local_mappings.map(&:name) end |
#mappings ⇒ Object
48 49 50 51 52 |
# File 'lib/flatter/mapper/mapping.rb', line 48 def mappings local_mappings.each_with_object({}) do |mapping, res| res[mapping.name] = mapping end end |
#read ⇒ Object
35 36 37 |
# File 'lib/flatter/mapper/mapping.rb', line 35 def read local_mappings.map(&:read_as_params).inject({}, :merge) end |
#writable_mapping_names ⇒ Object
58 59 60 |
# File 'lib/flatter/mapper/mapping.rb', line 58 def writable_mapping_names mappings.select{ |_, v| !v.writer? || v.writer != false }.keys end |
#write(params) ⇒ Object
39 40 41 |
# File 'lib/flatter/mapper/mapping.rb', line 39 def write(params) local_mappings.each{ |mapping| mapping.write_from_params(params) } end |