class Enumerize::Value
Attributes
value[R]
Public Class Methods
new(attr, name, value=nil)
click to toggle source
Calls superclass method
# File lib/enumerize/value.rb, line 12 def initialize(attr, name, value=nil) if self.class.method_defined?("#{name}?") warn("It's not recommended to use `#{name}` as a field value since `#{name}?` is defined. (#{attr.klass.name}##{attr.name})") end @attr = attr @value = value.nil? ? name.to_s : value super(name.to_s) @i18n_keys = @attr.i18n_scopes.map { |s| :"#{s}.#{self}" } @i18n_keys << :"enumerize.defaults.#{@attr.name}.#{self}" @i18n_keys << :"enumerize.#{@attr.name}.#{self}" @i18n_keys << ActiveSupport::Inflector.humanize(ActiveSupport::Inflector.underscore(self)) # humanize value if there are no translations @i18n_keys end
Public Instance Methods
==(other)
click to toggle source
Calls superclass method
# File lib/enumerize/value.rb, line 33 def ==(other) super(other.to_s) || value == other end
encode_with(coder)
click to toggle source
# File lib/enumerize/value.rb, line 37 def encode_with(coder) coder.represent_object(self.class.superclass, @value) end
text()
click to toggle source
# File lib/enumerize/value.rb, line 29 def text I18n.t(@i18n_keys[0], :default => @i18n_keys[1..-1]) if @i18n_keys end
Private Instance Methods
predicate_call(value)
click to toggle source
# File lib/enumerize/value.rb, line 43 def predicate_call(value) value == self end