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.



41
42
43
44
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 41

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.



24
25
26
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 24

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.



32
33
34
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 32

def steps
  @steps
end

Instance Method Details

#==(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)


142
143
144
145
146
147
148
149
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 142

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.



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

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:



85
86
87
88
89
90
91
92
93
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 85

def commit!
  return false if committed?

  steps.each(&:define!).freeze

  freeze

  true
end

#committed?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 100

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:



60
61
62
63
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 60

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:



110
111
112
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 110

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

#inspectString

Returns:

  • (String)


132
133
134
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 132

def inspect
  steps.inspect
end

#sizeInteger

Returns:

  • (Integer)


49
50
51
# File 'lib/convenient_service/service/plugins/can_have_sequential_steps/entities/step_collection.rb', line 49

def size
  steps.size
end

#to_argumentsConvenientService::Support::Arguments



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

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

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



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

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