Class: ActiveData::Attributes::Localized

Inherits:
Base
  • Object
show all
Defined in:
lib/active_data/attributes/localized.rb

Instance Attribute Summary

Attributes inherited from Base

#name, #options

Instance Method Summary collapse

Methods inherited from Base

#default, #default_blank?, #initialize, #type, #type_cast, #values

Constructor Details

This class inherits a constructor from ActiveData::Attributes::Base

Instance Method Details

#default_value(*args) ⇒ Object



5
6
7
# File 'lib/active_data/attributes/localized.rb', line 5

def default_value *args
  {}
end

#generate_class_methods(context) ⇒ Object



37
38
# File 'lib/active_data/attributes/localized.rb', line 37

def generate_class_methods context
end

#generate_instance_methods(context) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/active_data/attributes/localized.rb', line 9

def generate_instance_methods context
  context.class_eval <<-EOS
    def #{name}_translations
      read_attribute(:#{name})
    end

    def #{name}_translations= value
      write_attribute(:#{name}, value)
    end

    def #{name}
      read_localized_attribute(:#{name})
    end

    def #{name}= value
      write_localized_attribute(:#{name}, value)
    end

    def #{name}?
      read_localized_attribute(:#{name}).present?
    end

    def #{name}_before_type_cast
      read_localized_attribute_before_type_cast(:#{name})
    end
  EOS
end