class VariaModel::Attributes

Attributes

coercions[W]

Public Instance Methods

[]=(key, value) click to toggle source

Override setter to coerce the given value if a coercion is defined

# File lib/varia_model/attributes.rb, line 25
def []=(key, value)
  coerced_value = coercion(key).present? ? coercion(key).call(value) : value
  old_setter(key, coerced_value)
end
Also aliased as: old_setter
coercion(key) click to toggle source
# File lib/varia_model/attributes.rb, line 16
def coercion(key)
  self.coercions[key]
end
coercions() click to toggle source

@return [Hashie::Mash]

# File lib/varia_model/attributes.rb, line 12
def coercions
  @coercions ||= Hashie::Mash.new
end
container(path) click to toggle source

Return the containing Hashie::Mash of the given dotted path

@param [String] path

@return [Hashie::Mash, nil]

# File lib/varia_model/attributes.rb, line 35
def container(path)
  parts = path.split('.', 2)
  match = (self[parts[0].to_s] || self[parts[0].to_sym])
  if !parts[1] or match.nil?
    self
  else
    match.container(parts[1])
  end
end
dup() click to toggle source
# File lib/varia_model/attributes.rb, line 45
def dup
  mash = old_dup
  mash.coercions = self.coercions
  mash
end
Also aliased as: old_dup
old_dup()
Alias for: dup
old_setter(key, value)
Alias for: []=
set_coercion(key, fun) click to toggle source
# File lib/varia_model/attributes.rb, line 20
def set_coercion(key, fun)
  self.coercions[key] = fun
end