Class: Diesel::DataModel
- Inherits:
-
Object
- Object
- Diesel::DataModel
- Defined in:
- lib/diesel/data_model.rb
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
Instance Method Summary collapse
- #build(parameter_name, env) ⇒ Object
-
#initialize(definition) ⇒ DataModel
constructor
A new instance of DataModel.
Constructor Details
#initialize(definition) ⇒ DataModel
Returns a new instance of DataModel.
7 8 9 |
# File 'lib/diesel/data_model.rb', line 7 def initialize(definition) @definition = definition end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
5 6 7 |
# File 'lib/diesel/data_model.rb', line 5 def definition @definition end |
Instance Method Details
#build(parameter_name, env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/diesel/data_model.rb', line 11 def build(parameter_name, env) context = env[:context] h = context.get_attribute(parameter_name) return nil unless h json = definition.properties.reduce({}) do |m, (name, property)| name = name.to_sym m[name] = h[name] if h[name]; m end MultiJson.dump(json) end |