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
- #local_mappings ⇒ Object
- #mapping(name) ⇒ Object
- #mapping_names ⇒ Object
- #mappings ⇒ Object
- #read ⇒ Object
- #writable_mapping_names ⇒ Object
- #write(params) ⇒ Object
Instance Method Details
#[](name) ⇒ Object
64 65 66 |
# File 'lib/flatter/mapper/mapping.rb', line 64 def [](name) mappings[name.to_s].try(:read) end |
#[]=(name, value) ⇒ Object
68 69 70 |
# File 'lib/flatter/mapper/mapping.rb', line 68 def []=(name, value) mappings[name.to_s].try(:write, value) end |
#local_mappings ⇒ Object
46 47 48 |
# File 'lib/flatter/mapper/mapping.rb', line 46 def local_mappings @_local_mappings ||= self.class.mappings.values.map{ |factory| factory.create(self) } end |
#mapping(name) ⇒ Object
72 73 74 |
# File 'lib/flatter/mapper/mapping.rb', line 72 def mapping(name) mappings[name.to_s] end |
#mapping_names ⇒ Object
56 57 58 |
# File 'lib/flatter/mapper/mapping.rb', line 56 def mapping_names @_mapping_names ||= mappings.keys end |
#mappings ⇒ Object
50 51 52 53 54 |
# File 'lib/flatter/mapper/mapping.rb', line 50 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
60 61 62 |
# File 'lib/flatter/mapper/mapping.rb', line 60 def writable_mapping_names mappings.select{ |_, v| !v.writer? || v.writer != false }.keys end |
#write(params) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/flatter/mapper/mapping.rb', line 39 def write(params) params = params.with_indifferent_access local_mappings.each{ |mapping| mapping.write_from_params(params) } params end |