Module: Ork::Model
- Defined in:
- lib/ork/model.rb,
lib/ork/model/index.rb,
lib/ork/model/finders.rb,
lib/ork/model/associations.rb,
lib/ork/model/class_methods.rb
Defined Under Namespace
Modules: Associations, ClassMethods, Embedded, Finders Classes: Index
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#embedding ⇒ Object
readonly
Returns the value of attribute embedding.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(atts = {}) ⇒ Object
Initialize a model using a dictionary of attributes.
-
#update_attributes(atts) ⇒ Object
Write the dictionary of key-value pairs to the model.
-
#update_embedded_attributes(atts) ⇒ Object
Writhe the dictionary of key-value pairs of embedded objects.
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/ork/model.rb', line 6 def attributes @attributes end |
#embedding ⇒ Object (readonly)
Returns the value of attribute embedding.
6 7 8 |
# File 'lib/ork/model.rb', line 6 def @embedding end |
Class Method Details
.included(klass) ⇒ Object
8 9 10 11 |
# File 'lib/ork/model.rb', line 8 def self.included(klass) klass.extend(Ork::Model::ClassMethods) klass.extend(Ork::Model::Associations) end |
Instance Method Details
#initialize(atts = {}) ⇒ Object
Initialize a model using a dictionary of attributes.
Example:
u = User.new(:name => "John")
19 20 21 22 23 24 |
# File 'lib/ork/model.rb', line 19 def initialize(atts = {}) @attributes = {} @embedding = {} @_memo = {} update_attributes(model.defaults.merge(atts)) end |
#update_attributes(atts) ⇒ Object
Write the dictionary of key-value pairs to the model.
28 29 30 31 |
# File 'lib/ork/model.rb', line 28 def update_attributes(atts) atts.delete('_type') atts.each { |att, val| send(:"#{att}=", val) } end |
#update_embedded_attributes(atts) ⇒ Object
Writhe the dictionary of key-value pairs of embedded objects.
35 36 37 38 39 |
# File 'lib/ork/model.rb', line 35 def (atts) atts.each do |att, val| @embedding[att] = val end end |