Class: ConvenientService::Service::Plugins::CanHaveSequentialSteps::Entities::StepCollection

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ConvenientService::Support::Copyable

#copy

Constructor Details

#initialize(container:, 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.



36
37
38
39
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 36

def initialize(container:, steps: [])
  @container = container
  @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.



19
20
21
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 19

def container
  @container
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.



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

def steps
  @steps
end

Instance Method Details

#==(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)


137
138
139
140
141
142
143
144
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 137

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

  return false if container != other.container
  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.



120
121
122
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 120

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:



80
81
82
83
84
85
86
87
88
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 80

def commit!
  return false if committed?

  steps.each(&:define!).freeze

  freeze

  true
end

#committed?Boolean

Returns:

  • (Boolean)


95
96
97
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 95

def committed?
  steps.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:



55
56
57
58
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 55

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:



105
106
107
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 105

def each(&block)
  steps.each(&block)
end

#inspectString

Returns:

  • (String)


127
128
129
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 127

def inspect
  steps.inspect
end

#sizeInteger

Returns:

  • (Integer)


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

def size
  steps.size
end

#to_argumentsConvenientService::Support::Arguments



149
150
151
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 149

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

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



64
65
66
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 64

def with_organizer(organizer)
  copy(overrides: {kwargs: {steps: steps.map { |step| step.with_organizer(organizer) }}})
end