Class: ConvenientService::Service::Plugins::CanHaveConnectedSteps::Entities::Expressions::If

Inherits:
Base
  • Object
show all
Defined in:
lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#and?, #complex_if?, #else?, #empty?, #group?, #not?, #or?, #scalar?, #steps

Methods included from ConvenientService::Support::Copyable

#copy

Methods included from ConvenientService::Support::AbstractMethod

abstract_method

Constructor Details

#initialize(condition_expression, then_expression) ⇒ void



32
33
34
35
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 32

def initialize(condition_expression, then_expression)
  @condition_expression = condition_expression
  @then_expression = then_expression
end

Instance Attribute Details

#condition_expressionObject (readonly)

Returns the value of attribute condition_expression.



19
20
21
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 19

def condition_expression
  @condition_expression
end

#then_expressionObject (readonly)

Returns the value of attribute then_expression.



25
26
27
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 25

def then_expression
  @then_expression
end

Instance Method Details

#==(other) ⇒ Boolean?

Parameters:

  • other (Object)

    Can be any type.

Returns:

  • (Boolean, nil)


123
124
125
126
127
128
129
130
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 123

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

  return false if condition_expression != other.condition_expression
  return false if then_expression != other.then_expression

  true
end

#each_evaluated_step(&block) ⇒ ConvenientService::Service::Plugins::CanHaveConnectedSteps::Entities::Expressions::Base



89
90
91
92
93
94
95
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 89

def each_evaluated_step(&block)
  condition_expression.each_evaluated_step(&block)

  then_expression.each_evaluated_step(&block) if condition_expression.success?

  self
end

#each_step(&block) ⇒ ConvenientService::Service::Plugins::CanHaveConnectedSteps::Entities::Expressions::Base



77
78
79
80
81
82
83
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 77

def each_step(&block)
  condition_expression.each_step(&block)

  then_expression.each_step(&block)

  self
end

#error?Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
71
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 65

def error?
  return true if condition_expression.error?

  return then_expression.error? if condition_expression.success?

  false
end

#failure?Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 54

def failure?
  return true if condition_expression.failure?

  return then_expression.failure? if condition_expression.success?

  false
end

#if?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 115

def if?
  true
end

#inspectString

Returns:

  • (String)


108
109
110
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 108

def inspect
  "if #{condition_expression.inspect} then #{then_expression.inspect} end"
end

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



40
41
42
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 40

def result
  condition_expression.success? ? then_expression.result : condition_expression.result
end

#success?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 47

def success?
  condition_expression.success? && then_expression.success?
end

#to_argumentsConvenientService::Support::Arguments



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

def to_arguments
  Support::Arguments.new(condition_expression, then_expression)
end

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



101
102
103
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 101

def with_organizer(organizer)
  copy(overrides: {args: {0 => condition_expression.with_organizer(organizer), 1 => then_expression.with_organizer(organizer)}})
end