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
g(k)
Alias for: get_attribute
get(k)
Alias for: get_attribute
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
Also aliased as: get, g
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(k, v)
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
gets(keys)
Alias for: get_attributes
gs(k, v)
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
s(k,v)
Alias for: set_attribute
set(k,v)
Alias for: set_attribute
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
Also aliased as: set, s
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
sets(k_v_pairs)
Alias for: set_attributes
u(k)
Alias for: unset_attribute
unset(k)
Alias for: unset_attribute
unset_attribute(k) click to toggle source
# File lib/mongoo/attributes.rb, line 79
def unset_attribute(k)
  mongohash.dot_delete(k); true
end
Also aliased as: unset, u
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
unsets(keys)
Alias for: unset_attributes