Module: GenericViewMapper::Import::DSL
- Included in:
- Section
- Defined in:
- lib/generic_view_mapper/view/import.rb
Instance Method Summary collapse
- #from_json(source) ⇒ Object
- #from_yaml(source) ⇒ Object
- #import(hash) ⇒ Object
- #json(source) ⇒ Object
- #yaml(source) ⇒ Object
Instance Method Details
#from_json(source) ⇒ Object
17 18 19 |
# File 'lib/generic_view_mapper/view/import.rb', line 17 def from_json(source) Class.new(self) { json(source) } end |
#from_yaml(source) ⇒ Object
25 26 27 |
# File 'lib/generic_view_mapper/view/import.rb', line 25 def from_yaml(source) Class.new(self) { yaml(source) } end |
#import(hash) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/generic_view_mapper/view/import.rb', line 29 def import(hash) hash.each do |(k, v)| case v when Hash attribute(v[:name], v) when Array section(k) { v.each { |f| attribute(f[:name], f) } } end end end |
#json(source) ⇒ Object
13 14 15 |
# File 'lib/generic_view_mapper/view/import.rb', line 13 def json(source) import(MultiJson.decode(source, symbolize_keys: true)) end |
#yaml(source) ⇒ Object
21 22 23 |
# File 'lib/generic_view_mapper/view/import.rb', line 21 def yaml(source) import(YAML.safe_load(source).deep_symbolize_keys) end |