Class: Setsumei::Describable::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/setsumei/describable/attribute.rb

Direct Known Subclasses

ObjectAttribute

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {}
  self.name = name
  self.type = type
  self.lookup_key = options.delete(:from_within)
  self.options = options.tap { |o| o.delete :as_a }
end

Instance Attribute Details

#klassObject

Returns the value of attribute klass.



12
13
14
# File 'lib/setsumei/describable/attribute.rb', line 12

def klass
  @klass
end

#lookup_keyObject

Returns the value of attribute lookup_key.



12
13
14
# File 'lib/setsumei/describable/attribute.rb', line 12

def lookup_key
  @lookup_key
end

#nameObject

Returns the value of attribute name.



12
13
14
# File 'lib/setsumei/describable/attribute.rb', line 12

def name
  @name
end

#optionsObject

Returns the value of attribute options.



12
13
14
# File 'lib/setsumei/describable/attribute.rb', line 12

def options
  @options
end

#typeObject

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?

Returns:

  • (Boolean)


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, options)
  object.send accessor, value_from_hash(options[: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