Class: Orchestra::DSL::ObjectAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/orchestra/dsl/object_adapter.rb

Direct Known Subclasses

ClassAdapter, SingletonAdapter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, method_name, collection) ⇒ ObjectAdapter

Returns a new instance of ObjectAdapter.



24
25
26
27
28
# File 'lib/orchestra/dsl/object_adapter.rb', line 24

def initialize object, method_name, collection
  @collection = collection
  @method_name = method_name || :execute
  @object = object
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



22
23
24
# File 'lib/orchestra/dsl/object_adapter.rb', line 22

def collection
  @collection
end

#method_nameObject (readonly)

Returns the value of attribute method_name.



22
23
24
# File 'lib/orchestra/dsl/object_adapter.rb', line 22

def method_name
  @method_name
end

#objectObject (readonly)

Returns the value of attribute object.



22
23
24
# File 'lib/orchestra/dsl/object_adapter.rb', line 22

def object
  @object
end

Class Method Details

.build_step(object, args = {}) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/orchestra/dsl/object_adapter.rb', line 4

def self.build_step object, args = {}
  method_name = args.delete :method do :execute end
  collection = args.delete :iterates_over
  adapter_type = determine_type object, method_name
  adapter = adapter_type.new object, method_name, collection
  StepFactory.build adapter, args
end

.determine_type(object, method_name) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/orchestra/dsl/object_adapter.rb', line 12

def self.determine_type object, method_name
  if object.public_methods.include? method_name
    SingletonAdapter
  elsif object.kind_of? Class
    ClassAdapter
  else
    SingletonAdapter
  end
end

Instance Method Details

#build_context(state) ⇒ Object



30
31
32
# File 'lib/orchestra/dsl/object_adapter.rb', line 30

def build_context state
  ObjectContext.new self, state
end

#collection?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/orchestra/dsl/object_adapter.rb', line 34

def collection?
  @collection ? true : false
end

#context_classObject



38
39
40
# File 'lib/orchestra/dsl/object_adapter.rb', line 38

def context_class
  @context_class ||= Step.build_execution_context_class dependencies
end

#dependenciesObject



42
43
44
# File 'lib/orchestra/dsl/object_adapter.rb', line 42

def dependencies
  [collection, *object_method.dependencies].compact
end

#nameObject



46
47
48
49
50
51
52
# File 'lib/orchestra/dsl/object_adapter.rb', line 46

def name
  if method_name == :execute
    object.name
  else
    "#{object.name}##{method_name}"
  end
end