Class: Grumlin::Step

Inherits:
Steppable show all
Defined in:
lib/grumlin/step.rb

Constant Summary

Constants inherited from Steppable

Grumlin::Steppable::ALL_STEPS, Grumlin::Steppable::CONFIGURATION_STEPS, Grumlin::Steppable::REGULAR_STEPS, Grumlin::Steppable::START_STEPS

Instance Attribute Summary collapse

Attributes inherited from Steppable

#pool, #session_id

Instance Method Summary collapse

Methods inherited from Steppable

#step

Constructor Details

#initialize(name, args: [], params: {}, previous_step: nil, pool: nil, session_id: nil, middlewares: Grumlin.default_middlewares) ⇒ Step

TODO: replace pool, session_id and middlewares with a context?



7
8
9
10
11
12
13
14
15
16
# File 'lib/grumlin/step.rb', line 7

def initialize(name, args: [], params: {}, previous_step: nil, pool: nil, session_id: nil, # rubocop:disable Metrics/ParameterLists
               middlewares: Grumlin.default_middlewares)
  super(pool:, session_id:, middlewares:)

  @name = name.to_sym
  @args = args # TODO: add recursive validation: only json types or Step
  @params = params # TODO: add recursive validation: only json types
  @previous_step = previous_step
  @shortcut = shortcuts[@name]
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



4
5
6
# File 'lib/grumlin/step.rb', line 4

def args
  @args
end

#configuration_stepsObject (readonly)

Returns the value of attribute configuration_steps.



4
5
6
# File 'lib/grumlin/step.rb', line 4

def configuration_steps
  @configuration_steps
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/grumlin/step.rb', line 4

def name
  @name
end

#next_stepObject (readonly)

Returns the value of attribute next_step.



4
5
6
# File 'lib/grumlin/step.rb', line 4

def next_step
  @next_step
end

#paramsObject (readonly)

Returns the value of attribute params.



4
5
6
# File 'lib/grumlin/step.rb', line 4

def params
  @params
end

#previous_stepObject (readonly)

Returns the value of attribute previous_step.



4
5
6
# File 'lib/grumlin/step.rb', line 4

def previous_step
  @previous_step
end

#shortcutObject (readonly)

Returns the value of attribute shortcut.



4
5
6
# File 'lib/grumlin/step.rb', line 4

def shortcut
  @shortcut
end

Instance Method Details

#==(other) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/grumlin/step.rb', line 34

def ==(other)
  self.class == other.class &&
    @name == other.name &&
    @args == other.args &&
    @params == other.params &&
    @previous_step == other.previous_step &&
    shortcuts == other.shortcuts
end

#bytecode(no_return: false) ⇒ Object



57
58
59
# File 'lib/grumlin/step.rb', line 57

def bytecode(no_return: false)
  Grumlin::StepsSerializers::Bytecode.new(steps, no_return:)
end

#configuration_step?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/grumlin/step.rb', line 18

def configuration_step?
  CONFIGURATION_STEPS.include?(@name) || name.to_sym == :tx
end

#hasNextObject

rubocop:disable Naming/MethodName



65
66
67
68
69
70
# File 'lib/grumlin/step.rb', line 65

def hasNext # rubocop:disable Naming/MethodName
  to_enum.peek
  true
rescue StopIteration
  false
end

#inspectObject

TODO: add human readable mode



52
53
54
55
# File 'lib/grumlin/step.rb', line 52

def inspect
  conf_steps, regular_steps = Grumlin::StepsSerializers::HumanReadableBytecode.new(steps).serialize
  "#{conf_steps.any? ? conf_steps : nil}#{regular_steps}"
end

#iterateObject



80
81
82
# File 'lib/grumlin/step.rb', line 80

def iterate
  send_query(need_results: false)
end

#nextObject



61
62
63
# File 'lib/grumlin/step.rb', line 61

def next
  to_enum.next
end

#regular_step?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/grumlin/step.rb', line 26

def regular_step?
  REGULAR_STEPS.include?(@name)
end

#start_step?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/grumlin/step.rb', line 22

def start_step?
  START_STEPS.include?(@name)
end

#stepsObject



43
44
45
# File 'lib/grumlin/step.rb', line 43

def steps
  @steps ||= Grumlin::Steps.from(self)
end

#supported_step?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/grumlin/step.rb', line 30

def supported_step?
  ALL_STEPS.include?(@name)
end

#to_enumObject



72
73
74
# File 'lib/grumlin/step.rb', line 72

def to_enum
  @to_enum ||= toList.to_enum
end

#to_s(**params) ⇒ Object



47
48
49
# File 'lib/grumlin/step.rb', line 47

def to_s(**params)
  Grumlin::StepsSerializers::String.new(steps, **params).serialize
end

#toListObject



76
77
78
# File 'lib/grumlin/step.rb', line 76

def toList
  send_query(need_results: true)
end