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

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_namesObject



54
55
56
# File 'lib/flatter/mapper/mapping.rb', line 54

def mapping_names
  local_mappings.map(&:name)
end

#mappingsObject



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

#readObject



35
36
37
# File 'lib/flatter/mapper/mapping.rb', line 35

def read
  local_mappings.map(&:read_as_params).inject({}, :merge)
end

#writable_mapping_namesObject



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