Class: Bparity::Adapter::Subject

Inherits:
Object
  • Object
show all
Defined in:
lib/bparity/adapter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Subject

Returns a new instance of Subject.



35
36
37
38
# File 'lib/bparity/adapter.rb', line 35

def initialize(name)
  @name = name
  @operations = {}
end

Instance Attribute Details

#constructorObject

Returns the value of attribute constructor.



33
34
35
# File 'lib/bparity/adapter.rb', line 33

def constructor
  @constructor
end

#nameObject (readonly)

Returns the value of attribute name.



32
33
34
# File 'lib/bparity/adapter.rb', line 32

def name
  @name
end

#operationsObject (readonly)

Returns the value of attribute operations.



32
33
34
# File 'lib/bparity/adapter.rb', line 32

def operations
  @operations
end

#state_projectionObject

Returns the value of attribute state_projection.



33
34
35
# File 'lib/bparity/adapter.rb', line 33

def state_projection
  @state_projection
end

Instance Method Details

#build(context = {}) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/bparity/adapter.rb', line 49

def build(context = {})
  unless constructor
    raise ConfigurationError, "Adapter subject #{name} has no constructor. Add a construct block to the adapter."
  end

  constructor.call(context)
end

#construct(&block) ⇒ Object



40
# File 'lib/bparity/adapter.rb', line 40

def construct(&block) = self.constructor = block

#operation(name, &block) ⇒ Object



43
44
45
46
47
# File 'lib/bparity/adapter.rb', line 43

def operation(name, &block)
  item = Operation.new(name: name)
  OperationDsl.new(item).instance_eval(&block) if block
  operations[name] = item
end

#state(&block) ⇒ Object



41
# File 'lib/bparity/adapter.rb', line 41

def state(&block) = self.state_projection = block