Class: Setsumei::Describable::Attribute
- Inherits:
-
Object
- Object
- Setsumei::Describable::Attribute
- Defined in:
- lib/setsumei/describable/attribute.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#lookup_key ⇒ Object
Returns the value of attribute lookup_key.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(name, type, options = {}) ⇒ Attribute
constructor
A new instance of Attribute.
- #is_an_attribute_of_type?(other) ⇒ Boolean (also: #is_a?, #kind_of?)
- #set_value_on(object, options) ⇒ Object
- #value_for(pre_type_cast_value) ⇒ Object
Constructor Details
#initialize(name, type, options = {}) ⇒ Attribute
Returns a new instance of Attribute.
5 6 7 8 9 10 |
# File 'lib/setsumei/describable/attribute.rb', line 5 def initialize name, type, = {} self.name = name self.type = type self.lookup_key = .delete(:from_within) self. = .tap { |o| o.delete :as_a } end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
12 13 14 |
# File 'lib/setsumei/describable/attribute.rb', line 12 def klass @klass end |
#lookup_key ⇒ Object
Returns the value of attribute lookup_key.
12 13 14 |
# File 'lib/setsumei/describable/attribute.rb', line 12 def lookup_key @lookup_key end |
#name ⇒ Object
Returns the value of attribute name.
12 13 14 |
# File 'lib/setsumei/describable/attribute.rb', line 12 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
12 13 14 |
# File 'lib/setsumei/describable/attribute.rb', line 12 def @options end |
#type ⇒ Object
Returns the value of attribute type.
12 13 14 |
# File 'lib/setsumei/describable/attribute.rb', line 12 def type @type end |
Instance Method Details
#is_an_attribute_of_type?(other) ⇒ Boolean Also known as: is_a?, kind_of?
14 15 16 |
# File 'lib/setsumei/describable/attribute.rb', line 14 def is_an_attribute_of_type?(other) type == other end |
#set_value_on(object, options) ⇒ Object
24 25 26 |
# File 'lib/setsumei/describable/attribute.rb', line 24 def set_value_on(object, ) object.send accessor, value_from_hash([:from_value_in]) end |
#value_for(pre_type_cast_value) ⇒ Object
20 21 22 |
# File 'lib/setsumei/describable/attribute.rb', line 20 def value_for(pre_type_cast_value) type.cast pre_type_cast_value end |