module MongoModel::Attributes
Public Class Methods
new(attrs={}, options={}) { |self| ... }
click to toggle source
# File lib/mongomodel/concerns/attributes.rb, line 7 def initialize(attrs={}, options={}) assign_attributes(attrs || {}, options) yield self if block_given? end
Public Instance Methods
assign_attributes(attrs, options={})
click to toggle source
# File lib/mongomodel/concerns/attributes.rb, line 16 def assign_attributes(attrs, options={}) return unless attrs attrs.each do |attr, value| if respond_to?("#{attr}=") send("#{attr}=", value) else write_attribute(attr, value) end end end
attributes()
click to toggle source
# File lib/mongomodel/concerns/attributes.rb, line 12 def attributes @attributes ||= Attributes::Store.new(self) end
attributes=(attrs)
click to toggle source
# File lib/mongomodel/concerns/attributes.rb, line 28 def attributes=(attrs) assign_attributes(attrs) end
dup()
click to toggle source
Returns duplicated record with unfreezed attributes.
Calls superclass method
# File lib/mongomodel/concerns/attributes.rb, line 41 def dup obj = super obj.instance_variable_set('@attributes', instance_variable_get('@attributes').dup) obj end
embedded_documents()
click to toggle source
# File lib/mongomodel/concerns/attributes.rb, line 51 def embedded_documents docs = [] docs.concat attributes.values.select { |attr| attr.is_a?(EmbeddedDocument) } attributes.values.select { |attr| attr.is_a?(Collection) }.each do |collection| docs.concat collection.embedded_documents end attributes.values.select { |attr| attr.is_a?(Map) && attr.to <= EmbeddedDocument }.each do |map| docs.concat map.values end docs end
freeze()
click to toggle source
# File lib/mongomodel/concerns/attributes.rb, line 32 def freeze attributes.freeze; self end
frozen?()
click to toggle source
# File lib/mongomodel/concerns/attributes.rb, line 36 def frozen? attributes.frozen? end
to_mongo()
click to toggle source
# File lib/mongomodel/concerns/attributes.rb, line 47 def to_mongo attributes.to_mongo end
Protected Instance Methods
sanitize_for_mass_assignment(attrs, options={})
click to toggle source
# File lib/mongomodel/concerns/attributes.rb, line 68 def sanitize_for_mass_assignment(attrs, options={}) attrs end