Class: Enumy::Rails::Enum
Instance Attribute Summary
Attributes inherited from Enum
#key
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Enum
all, define, find, find_by, #to_s
Constructor Details
#initialize(key, **attrs) ⇒ Enum
Returns a new instance of Enum.
12
13
14
15
|
# File 'lib/enumy/rails/enum.rb', line 12
def initialize(key, **attrs)
raise Errors::KeyMissingError.new(self) if key.nil?
super(key: key.to_sym, **attrs)
end
|
Class Method Details
.i18n_scope ⇒ Object
39
40
41
|
# File 'lib/enumy/rails/enum.rb', line 39
def i18n_scope
:enum
end
|
.model_name ⇒ Object
35
36
37
|
# File 'lib/enumy/rails/enum.rb', line 35
def model_name
@model_name ||= ::ActiveModel::Name.new(self, nil, self.name.to_s)
end
|
Instance Method Details
#human_attribute_name(attribute) ⇒ Object
21
22
23
|
# File 'lib/enumy/rails/enum.rb', line 21
def human_attribute_name(attribute)
I18n.t("#{self.class.i18n_scope}.attributes.models.#{self.class.model_name.i18n_key}/#{self.key}.#{attribute}")
end
|
#inspect ⇒ Object
29
30
31
|
# File 'lib/enumy/rails/enum.rb', line 29
def inspect
"#<#{self.class.name} #{attributes.map { |name, value| "#{name}: #{value.inspect}" }.join(', ')}>"
end
|
#name ⇒ Object
25
26
27
|
# File 'lib/enumy/rails/enum.rb', line 25
def name
human_attribute_name(:key)
end
|
#titleize ⇒ Object
17
18
19
|
# File 'lib/enumy/rails/enum.rb', line 17
def titleize
key.to_s.titleize
end
|