module Mongoo::Attributes::InstanceMethods
Public Instance Methods
attributes()
click to toggle source
# File lib/mongoo/attributes.rb, line 104 def attributes mongohash.to_key_value end
get_attribute(k)
click to toggle source
# File lib/mongoo/attributes.rb, line 46 def get_attribute(k) unless known_attribute?(k) raise Mongoo::UnknownAttributeError, k end mongohash.dot_get(k.to_s) end
get_attributes(keys)
click to toggle source
# File lib/mongoo/attributes.rb, line 92 def get_attributes(keys) found = {} keys.each { |k| found[k.to_s] = get_attribute(k) } found end
Also aliased as: gets
get_or_set_attribute(k, v)
click to toggle source
# File lib/mongoo/attributes.rb, line 73 def get_or_set_attribute(k, v) get_attribute(k) || set_attribute(k, v) end
Also aliased as: get_or_set, gs
id()
click to toggle source
# File lib/mongoo/attributes.rb, line 108 def id get "_id" end
id=(val)
click to toggle source
# File lib/mongoo/attributes.rb, line 112 def id=(val) set "_id", val end
known_attribute?(k)
click to toggle source
# File lib/mongoo/attributes.rb, line 38 def known_attribute?(k) self.class.known_attribute?(k) end
read_attribute_for_validation(key)
click to toggle source
# File lib/mongoo/attributes.rb, line 42 def read_attribute_for_validation(key) get_attribute(key) end
set_attribute(k,v)
click to toggle source
# File lib/mongoo/attributes.rb, line 55 def set_attribute(k,v) unless known_attribute?(k) if self.respond_to?("#{k}=") self.send("#{k}=", v) return v else raise Mongoo::UnknownAttributeError, k end end unless k.to_s == "_id" || v.nil? field_type = self.class.attributes[k.to_s][:type] v = Mongoo::AttributeSanitizer.sanitize(field_type, v) end mongohash.dot_set(k.to_s,v); v end
set_attributes(k_v_pairs)
click to toggle source
# File lib/mongoo/attributes.rb, line 85 def set_attributes(k_v_pairs) k_v_pairs.each do |k,v| set_attribute(k,v) end end
Also aliased as: sets
unset_attribute(k)
click to toggle source
# File lib/mongoo/attributes.rb, line 79 def unset_attribute(k) mongohash.dot_delete(k); true end
unset_attributes(keys)
click to toggle source
# File lib/mongoo/attributes.rb, line 99 def unset_attributes(keys) keys.each { |k| unset_attribute(k) }; true end
Also aliased as: unsets