Class: Enumerize::Value
- Inherits:
-
String
- Object
- String
- Enumerize::Value
show all
- Includes:
- Predicatable
- Defined in:
- lib/enumerize/value.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
#respond_to_missing?
Constructor Details
#initialize(attr, name, value = nil) ⇒ Value
Returns a new instance of Value.
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/enumerize/value.rb', line 12
def initialize(attr, name, value=nil)
@attr = attr
@value = value.nil? ? name.to_s : value
super(name.to_s)
@i18n_keys = @attr.i18n_scopes.map do |s|
scope = Utils.call_if_callable(s, @value)
:"#{scope}.#{self}"
end
@i18n_keys << :"enumerize.defaults.#{@attr.name}.#{self}"
@i18n_keys << :"enumerize.#{@attr.name}.#{self}"
@i18n_keys << ActiveSupport::Inflector.humanize(ActiveSupport::Inflector.underscore(self)) @i18n_keys
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Enumerize::Predicatable
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
10
11
12
|
# File 'lib/enumerize/value.rb', line 10
def value
@value
end
|
Instance Method Details
#==(other) ⇒ Object
33
34
35
|
# File 'lib/enumerize/value.rb', line 33
def ==(other)
super(other.to_s) || value == other
end
|
#as_json ⇒ Object
41
42
43
|
# File 'lib/enumerize/value.rb', line 41
def as_json(*)
to_s
end
|
#encode_with(coder) ⇒ Object
37
38
39
|
# File 'lib/enumerize/value.rb', line 37
def encode_with(coder)
coder.represent_object(self.class.superclass, @value)
end
|
#text ⇒ Object
29
30
31
|
# File 'lib/enumerize/value.rb', line 29
def text
I18n.t(@i18n_keys[0], :default => @i18n_keys[1..-1]) if @i18n_keys
end
|