Class: Setsumei::Describable::ObjectAttribute

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

Instance Attribute Summary collapse

Attributes inherited from Attribute

#lookup_key, #name, #options, #type

Instance Method Summary collapse

Methods inherited from Attribute

#is_an_attribute_of_type?, #set_value_on, #value_for

Constructor Details

#initialize(type = nil) ⇒ ObjectAttribute

Returns a new instance of ObjectAttribute.



5
6
7
# File 'lib/setsumei/describable/object_attribute.rb', line 5

def initialize type = nil
  @klass = type || Object
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



8
9
10
# File 'lib/setsumei/describable/object_attribute.rb', line 8

def klass
  @klass
end

Instance Method Details

#==(other) ⇒ Object



10
11
12
# File 'lib/setsumei/describable/object_attribute.rb', line 10

def == other
  :object == other || ObjectAttribute == other || klass == other
end

#cast(data) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/setsumei/describable/object_attribute.rb', line 14

def cast data
  return nil if data.nil? || data.empty?

  begin
    klass.create_from data
  rescue NoMethodError
    Build.a klass, from: data
  end
end