Class: ConvenientService::Service::Plugins::CanHaveConnectedSteps::Entities::StepCollection

Inherits:
Object
  • Object
show all
Includes:
ConvenientService::Support::Copyable, Enumerable
Defined in:
lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ConvenientService::Support::Copyable

#copy

Constructor Details

#initialize(container:, expression: Entities::Expressions::Empty.new, steps: []) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:



53
54
55
56
57
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb', line 53

def initialize(container:, expression: Entities::Expressions::Empty.new, steps: [])
  @container = container
  @expression = expression
  @steps = steps
end

Instance Attribute Details

#containerObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



27
28
29
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb', line 27

def container
  @container
end

#expressionConvenientService::Service::Plugins::CanHaveConnectedSteps::Entities::Expressions::Base



35
36
37
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb', line 35

def expression
  @expression
end

#stepsObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



43
44
45
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb', line 43

def steps
  @steps
end

Instance Method Details

#==(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)


187
188
189
190
191
192
193
194
195
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb', line 187

def ==(other)
  return unless other.instance_of?(self.class)

  return false if container != other.container
  return false if expression != other.expression
  return false if steps != other.steps

  true
end

#[](index) ⇒ ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step

Note:

Works in a similar way as ‘Array#[]`.

Returns step by index.



170
171
172
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb', line 170

def [](index)
  steps[index]
end

#commit!Boolean

Returns true if called for the first time, false otherwise (similarly as Kernel#require).

Returns:

  • (Boolean)

    true if called for the first time, false otherwise (similarly as Kernel#require).

See Also:



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb', line 108

def commit!
  return false if committed?

  expression.each_step(&:define!).freeze

  steps.freeze

  freeze

  true
end

#committed?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb', line 125

def committed?
  expression.frozen?
end

#create(*args, **kwargs) ⇒ ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • args (Array<Object>)
  • kwargs (Hash{Symbol => Object})

Returns:



81
82
83
84
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb', line 81

def create(*args, **kwargs)
  step_class.new(*args, **kwargs.merge(container: container, index: next_available_index))
    .tap { |step| steps << step }
end

#each(&block) ⇒ Array<ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step>, Enumerator

Parameters:

  • block (Proc, nil)

Returns:



135
136
137
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb', line 135

def each(&block)
  expression.each_step(&block)
end

#each_evaluated_step(&block) ⇒ Array<ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step>, Enumerator

Parameters:

  • block (Proc, nil)

Returns:



155
156
157
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb', line 155

def each_evaluated_step(&block)
  expression.each_evaluated_step(&block)
end

#each_step(&block) ⇒ Array<ConvenientService::Service::Plugins::CanHaveSteps::Entities::Step>, Enumerator

Parameters:

  • block (Proc, nil)

Returns:



145
146
147
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb', line 145

def each_step(&block)
  expression.each_step(&block)
end

#inspectString

Returns:

  • (String)


177
178
179
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb', line 177

def inspect
  expression.inspect
end

#resultConvenientService::Service::Plugins::HasJSendResult::Entities::Result



70
71
72
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb', line 70

def result
  expression.result
end

#sizeInteger

Returns:

  • (Integer)


62
63
64
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb', line 62

def size
  steps.size
end

#to_argumentsConvenientService::Support::Arguments



200
201
202
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb', line 200

def to_arguments
  Support::Arguments.new(container: container, expression: expression, steps: steps)
end

#with_organizer(organizer) ⇒ ConvenientService::Service::Plugins::CanHaveConnectedSteps::Entities::StepCollection



90
91
92
93
94
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/step_collection.rb', line 90

def with_organizer(organizer)
  expression_with_organizer = expression.with_organizer(organizer)

  copy(overrides: {kwargs: {expression: expression_with_organizer, steps: expression_with_organizer.steps}})
end