Class: Translatable::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/translatable/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(origin_model) ⇒ Base

Returns a new instance of Base.



5
6
7
# File 'lib/translatable/base.rb', line 5

def initialize origin_model
  @origin_model = origin_model
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



3
4
5
# File 'lib/translatable/base.rb', line 3

def fields
  @fields
end

#origin_keyObject (readonly)

Returns the value of attribute origin_key.



3
4
5
# File 'lib/translatable/base.rb', line 3

def origin_key
  @origin_key
end

#origin_reflection_nameObject (readonly) Also known as: or_name

Returns the value of attribute origin_reflection_name.



3
4
5
# File 'lib/translatable/base.rb', line 3

def origin_reflection_name
  @origin_reflection_name
end

#translation_modelObject (readonly) Also known as: t_model

ACCESS



32
33
34
# File 'lib/translatable/base.rb', line 32

def translation_model
  @translation_model
end

Instance Method Details

#class_name(model_name) ⇒ Object



14
15
16
# File 'lib/translatable/base.rb', line 14

def class_name(model_name)
  @translation_model = prepare_model model_name
end

#field(*args) ⇒ Object

API



10
11
12
# File 'lib/translatable/base.rb', line 10

def field(*args)
  (@fields ||= []) << set_mapping(*args)
end

#foreign_key(key_name) ⇒ Object



18
19
20
# File 'lib/translatable/base.rb', line 18

def foreign_key(key_name)
  @origin_key = key_name.to_sym
end

#locale_columnObject



46
47
48
# File 'lib/translatable/base.rb', line 46

def locale_column
  @locale_column || (@locale_column = :locale)
end

#locale_key(key_name, opts = {}) ⇒ Object



26
27
28
29
# File 'lib/translatable/base.rb', line 26

def locale_key(key_name, opts = {})
  set_mapping key_name, opts
  @locale_column = key_name.to_sym
end

#mappingObject



50
51
52
53
54
55
56
# File 'lib/translatable/base.rb', line 50

def mapping
  unless @mapping_defined
    (@mapping ||= {})[locale_column] ||= :locale
    @mapping_defined = true
  end
  @mapping || {}
end

#reflection_name(reflection) ⇒ Object



22
23
24
# File 'lib/translatable/base.rb', line 22

def reflection_name(reflection)
  @origin_reflection_name = reflection.to_sym
end