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

- (Object) method_missing(method_id, *args, &block)



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 we haven't generated any methods yet, generate them, then
  # see if we've created the method we're looking for.
  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

- (Object) attributes

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

- (Object) force_attributes=(new_attributes)



37
38
39
# File 'lib/mongo_odm/document/attribute_methods.rb', line 37

def force_attributes=(new_attributes)
  send(:attributes=, new_attributes, true)
end

- (Object) freeze



52
53
54
# File 'lib/mongo_odm/document/attribute_methods.rb', line 52

def freeze
  @attributes.freeze; super
end

- (Boolean) has_attribute?(name)



56
57
58
# File 'lib/mongo_odm/document/attribute_methods.rb', line 56

def has_attribute?(name)
  @attributes.has_key?(name)
end

- (Object) initialize(attrs = {})



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

- (Object) load_attributes_or_defaults(attrs)



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

- (Object) remove_attribute(name)



65
66
67
# File 'lib/mongo_odm/document/attribute_methods.rb', line 65

def remove_attribute(name)
  @attributes.delete(name)
end

- (Boolean) respond_to?(*args)



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