Module: GettextColumnMapping::ParentLevel::AttrMethods

Defined in:
lib/gettext_column_mapping/parent_level/attr_methods.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/gettext_column_mapping/parent_level/attr_methods.rb', line 5

def self.extended(base)
  base.class_eval do 
    class << self
      def inherited_with_column_mapping_parent_level(subclass)
        self.inherited_without_column_mapping_parent_level(subclass)

        parent = GettextColumnMapping::ParentLevel.parent_attributes_translation(subclass.to_s)
        attributes = GettextColumnMapping::ParentLevel.column_attributes_translation(subclass.to_s)
        subclass.gettext_column_mapping_accessor(attributes,parent)
      end
      alias_method_chain :inherited, :column_mapping_parent_level
    end
  end
end

Instance Method Details

#gettext_column_mapping_accessor(method_syms = [], parent = nil) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/gettext_column_mapping/parent_level/attr_methods.rb', line 20

def gettext_column_mapping_accessor(method_syms=[],parent=nil)
  if parent
    parent_association = parent[:association]
    parent_key = parent[:key]
  end

  class_eval(<<-CODE,__FILE__,__LINE__)
    def msgid_for_attribute(method)
      parent_record = #{parent_association ? parent_association : 'nil'}
      GettextColumnMapping::ParentLevel.prefix_method(self,method,parent_record,'#{parent_key}')
    end
  CODE

  [method_syms].flatten.each do |method_sym|
    class_eval(<<-STR,__FILE__,__LINE__)

              def #{method_sym}
                s_(msgid_for_attribute('#{method_sym}'))
              end
              STR
  end
end