Module: MongoODM::Document::AttributeMethods::InstanceMethods
- Defined in:
- lib/mongo_odm/document/attribute_methods.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_id, *args, &block) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/mongo_odm/document/attribute_methods.rb', line 69
def method_missing(method_id, *args, &block)
if !self.class.attribute_methods_generated?
self.class.define_attribute_methods_for_fields
method_name = method_id.to_s
guard_private_attribute_method!(method_name, args)
send(method_id, *args, &block)
else
super
end
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
29
30
31
|
# File 'lib/mongo_odm/document/attribute_methods.rb', line 29
def attributes
@attributes
end
|
Instance Method Details
#force_attributes=(new_attributes) ⇒ Object
37
38
39
|
# File 'lib/mongo_odm/document/attribute_methods.rb', line 37
def force_attributes=(new_attributes)
send(:attributes=, new_attributes, true)
end
|
#freeze ⇒ Object
52
53
54
|
# File 'lib/mongo_odm/document/attribute_methods.rb', line 52
def freeze
@attributes.freeze; super
end
|
#has_attribute?(name) ⇒ Boolean
56
57
58
|
# File 'lib/mongo_odm/document/attribute_methods.rb', line 56
def has_attribute?(name)
@attributes.has_key?(name)
end
|
#initialize(attrs = {}) ⇒ Object
31
32
33
34
35
|
# File 'lib/mongo_odm/document/attribute_methods.rb', line 31
def initialize(attrs = {})
@attributes = {:_class => self.class.name}.with_indifferent_access
load_attributes_or_defaults(attrs)
self
end
|
#load_attributes_or_defaults(attrs) ⇒ Object
60
61
62
63
|
# File 'lib/mongo_odm/document/attribute_methods.rb', line 60
def load_attributes_or_defaults(attrs)
attrs = self.class.default_attributes.merge(attrs)
self.force_attributes = attrs
end
|
#remove_attribute(name) ⇒ Object
65
66
67
|
# File 'lib/mongo_odm/document/attribute_methods.rb', line 65
def remove_attribute(name)
@attributes.delete(name)
end
|
#respond_to?(*args) ⇒ Boolean
82
83
84
85
|
# File 'lib/mongo_odm/document/attribute_methods.rb', line 82
def respond_to?(*args)
self.class.define_attribute_methods_for_fields
super
end
|