Module: ActsAsMoonable::Humanable::ClassMethods

Defined in:
lib/acts_as_moonable/humanable.rb

Instance Method Summary collapse

Instance Method Details

#human_action_name(action, views = "defaults") ⇒ Object



10
11
12
# File 'lib/acts_as_moonable/humanable.rb', line 10

def human_action_name action, views="defaults"
  I18n.t("#{views}.action.#{action}", model: self.model_name.human)
end

#human_array_choices(enum_name) ⇒ Object



23
24
25
26
# File 'lib/acts_as_moonable/humanable.rb', line 23

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

#human_enum_choices(enum_name) ⇒ Object



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

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

#human_enum_name(enum_name, enum_value) ⇒ Object



14
15
16
# File 'lib/acts_as_moonable/humanable.rb', line 14

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

#i18n_attribute_name(attr) ⇒ Object



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

def i18n_attribute_name attr
  self.human_attribute_name attr
end