Class: RailsAttrEnum::EntryValue
- Inherits:
-
Struct
- Object
- Struct
- RailsAttrEnum::EntryValue
- Defined in:
- lib/rails_attr_enum/entry_value.rb
Overview
Forwarding class for actual attribute value
Instance Attribute Summary collapse
-
#attr_name ⇒ Object
Returns the value of attribute attr_name.
-
#enum ⇒ Object
Returns the value of attribute enum.
-
#model ⇒ Object
Returns the value of attribute model.
Instance Method Summary collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rails_attr_enum/entry_value.rb', line 8 def method_missing(name, *args, &block) default = proc { value.send(name, *args, &block) } if matches = /^(.*?)((\?|!)?)$/.match(name) const_name = matches[1].to_s.upcase if enum.const_defined?(const_name) case matches[2] when '?' value == enum.const_get(const_name) when '!' self.value = enum.const_get(const_name) else enum.const_get(const_name) end else default.call end else default.call end end |
Instance Attribute Details
#attr_name ⇒ Object
Returns the value of attribute attr_name
5 6 7 |
# File 'lib/rails_attr_enum/entry_value.rb', line 5 def attr_name @attr_name end |
#enum ⇒ Object
Returns the value of attribute enum
5 6 7 |
# File 'lib/rails_attr_enum/entry_value.rb', line 5 def enum @enum end |
#model ⇒ Object
Returns the value of attribute model
5 6 7 |
# File 'lib/rails_attr_enum/entry_value.rb', line 5 def model @model end |
Instance Method Details
#key ⇒ Object
30 31 32 |
# File 'lib/rails_attr_enum/entry_value.rb', line 30 def key enum.get_key(value) end |
#value ⇒ Object
34 35 36 |
# File 'lib/rails_attr_enum/entry_value.rb', line 34 def value model.read_attribute(attr_name) end |