Class: Interfacets::Shared::Entities::Specs::Handlers::Reference

Inherits:
Handler
  • Object
show all
Defined in:
lib/interfacets/shared/entities/specs/handlers.rb

Instance Attribute Summary

Attributes inherited from Handler

#cache, #entity, #spec

Instance Method Summary collapse

Methods inherited from Handler

#initialize, #type, #unwrap, #wrap

Constructor Details

This class inherits a constructor from Interfacets::Shared::Entities::Specs::Handlers::Handler

Instance Method Details

#build(**attributes) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
# File 'lib/interfacets/shared/entities/specs/handlers.rb', line 67

def build(**attributes)
  value = entity.instance_exec(&spec.builder)
  attributes.each do |name, val|
    value.send("#{name}=", val)
  end

  # TODO: make sure this is right
  # set(value)

  wrap(value)
end

#collection? ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/interfacets/shared/entities/specs/handlers.rb', line 46

def collection?
  false
end

#get ⇒ Object



54
55
56
57
58
59
60
# File 'lib/interfacets/shared/entities/specs/handlers.rb', line 54

def get
  wrap(entity.instance_exec(&spec.getter))
    .tap {
      @cache = {}
      @cache[_1&.store] = _1
    }
end

#reference? ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/interfacets/shared/entities/specs/handlers.rb', line 50

def reference?
  true
end

#set(val) ⇒ Object



62
63
64
65
# File 'lib/interfacets/shared/entities/specs/handlers.rb', line 62

def set(val)
  entity.instance_exec(unwrap(val), &spec.setter)
  wrap(val)
end