Module: ActsAsRailable::Humanable::ClassMethods

Defined in:
lib/acts_as_railable/humanable.rb

Instance Method Summary collapse

Instance Method Details

#i18n_action_name(name, default_name = nil) ⇒ Object



10
11
12
13
14
15
# File 'lib/acts_as_railable/humanable.rb', line 10

def i18n_action_name name, default_name=nil
  action_key = "#{self.table_name}.action.#{name}"
  default_key = "helper.action.#{name}" # unless I18n.exists? key
  default_name ||= name.to_s.capitalize
  I18n.t(action_key, model: self.model_name.human, default: [ default_key.to_sym, default_name ])
end

#i18n_array_choices(enum_name) ⇒ Object

CURRENCIES = %w( CNY USD EUR GBP JPY ) i18n_array_choices(:currency)



31
32
33
34
# File 'lib/acts_as_railable/humanable.rb', line 31

def i18n_array_choices enum_name
  array_values = self.const_get enum_name.to_s.pluralize.upcase
  array_values.map { |enum_value| [ self.i18n_enum_name(enum_name, enum_value), enum_value ] }
end

#i18n_attribute_name(attr) ⇒ Object



6
7
8
# File 'lib/acts_as_railable/humanable.rb', line 6

def i18n_attribute_name attr
  self.human_attribute_name attr
end

#i18n_enum_choices(enum_name) ⇒ Object

enum status: { edited: 0, published: 1, approved: 2, trashed: 3 } i18n_enum_choices(:status)



24
25
26
27
# File 'lib/acts_as_railable/humanable.rb', line 24

def i18n_enum_choices enum_name
  enum_hash = self.public_send enum_name.to_s.pluralize
  enum_hash.keys.map { |enum_value| [ self.i18n_enum_name(enum_name, enum_value), enum_value ] }
end

#i18n_enum_name(enum_name, enum_value) ⇒ Object

i18n_enum_name(:status, :edited)



18
19
20
# File 'lib/acts_as_railable/humanable.rb', line 18

def i18n_enum_name(enum_name, enum_value)
  self.human_attribute_name "#{enum_name}.#{enum_value}"
end