Class: Dataset::Record::Model
- Inherits:
-
Object
- Object
- Dataset::Record::Model
- Defined in:
- lib/dataset/record/model.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#session_binding ⇒ Object
readonly
Returns the value of attribute session_binding.
-
#symbolic_name ⇒ Object
readonly
Returns the value of attribute symbolic_name.
Instance Method Summary collapse
- #create ⇒ Object
- #id ⇒ Object
-
#initialize(meta, attributes, symbolic_name, session_binding) ⇒ Model
constructor
A new instance of Model.
- #record_class ⇒ Object
- #to_hash ⇒ Object
- #to_model ⇒ Object
Constructor Details
#initialize(meta, attributes, symbolic_name, session_binding) ⇒ Model
Returns a new instance of Model.
7 8 9 10 11 12 |
# File 'lib/dataset/record/model.rb', line 7 def initialize(, attributes, symbolic_name, session_binding) @meta = @attributes = attributes.stringify_keys @symbolic_name = symbolic_name || object_id @session_binding = session_binding end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/dataset/record/model.rb', line 5 def attributes @attributes end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
5 6 7 |
# File 'lib/dataset/record/model.rb', line 5 def @meta end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
5 6 7 |
# File 'lib/dataset/record/model.rb', line 5 def model @model end |
#session_binding ⇒ Object (readonly)
Returns the value of attribute session_binding.
5 6 7 |
# File 'lib/dataset/record/model.rb', line 5 def session_binding @session_binding end |
#symbolic_name ⇒ Object (readonly)
Returns the value of attribute symbolic_name.
5 6 7 |
# File 'lib/dataset/record/model.rb', line 5 def symbolic_name @symbolic_name end |
Instance Method Details
#create ⇒ Object
22 23 24 25 26 |
# File 'lib/dataset/record/model.rb', line 22 def create model = to_model model.save! model end |
#id ⇒ Object
18 19 20 |
# File 'lib/dataset/record/model.rb', line 18 def id model.id end |
#record_class ⇒ Object
14 15 16 |
# File 'lib/dataset/record/model.rb', line 14 def record_class .record_class end |
#to_hash ⇒ Object
28 29 30 |
# File 'lib/dataset/record/model.rb', line 28 def to_hash to_model.attributes end |
#to_model ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/dataset/record/model.rb', line 32 def to_model @model ||= begin m = .record_class.new attributes.each do |k,v| if reflection = record_class.reflect_on_association(k.to_sym) case v when Symbol v = session_binding.find_model(reflection.klass, v) end end m.send "#{k}=", v end m end end |