Module: CouchRest::LocalisedProperties

Extended by:
ActiveSupport::Concern
Defined in:
lib/couchrest_localised_properties.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#read_localised_attribute(property) ⇒ Object



12
13
14
15
# File 'lib/couchrest_localised_properties.rb', line 12

def read_localised_attribute(property)
  attr = (self[find_property!(property).to_s] || {})
  attr[I18n.locale.to_s] || attr[I18n.default_locale.to_s]
end

#write_localised_attribute(property, value) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/couchrest_localised_properties.rb', line 17

def write_localised_attribute(property, value)
  prop = find_property!(property)
  key = prop.to_s
  if value.is_a?(Hash) # from mass-asign
    self[key] = value
    self[key].each do |k,v|
      self[key][k] = prop.cast(self, v)
    end
  else
    value = prop.is_a?(String) ? value : prop.cast(self, value)
    couchrest_attribute_will_change!(prop.to_s) if use_dirty? && self[prop.to_s] != value
    self[key] ||= { }
    self[key][I18n.locale.to_s] = value
  end
end