Module: CurlyMustache::Attributes::InstanceMethods

Defined in:
lib/curly_mustache/attributes.rb

Instance Method Summary collapse

Instance Method Details

#attributesObject



47
48
49
# File 'lib/curly_mustache/attributes.rb', line 47

def attributes
  @attributes.dup
end

#attributes=(hash) ⇒ Object



43
44
45
# File 'lib/curly_mustache/attributes.rb', line 43

def attributes=(hash)
  hash.stringify_keys.each{ |k, v| write_attribute(k, v) }
end

#read_attribute(name) ⇒ Object



51
52
53
# File 'lib/curly_mustache/attributes.rb', line 51

def read_attribute(name)
  @attributes[name.to_s]
end

#write_attribute(name, value) ⇒ Object



55
56
57
58
# File 'lib/curly_mustache/attributes.rb', line 55

def write_attribute(name, value)
  send("#{name}_will_change!") # ActiveModel::Dirty
  @attributes[name.to_s] = value
end

#write_attribute_with_id_guard(name, value) ⇒ Object

Raises:



67
68
69
70
# File 'lib/curly_mustache/attributes.rb', line 67

def write_attribute_with_id_guard(name, value)
  raise IdNotSettableError, "not allowed to set id" if name.to_s == "id" and !allow_settable_id
  write_attribute_without_id_guard(name, value)
end

#write_attribute_with_typecast(name, value) ⇒ Object



60
61
62
63
# File 'lib/curly_mustache/attributes.rb', line 60

def write_attribute_with_typecast(name, value)
  casted_value = attribute_manager[name].cast(value)
  write_attribute_without_typecast(name, casted_value)
end