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)


128
129
130
131
132
133
134
135
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 128

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



94
95
96
97
98
99
100
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 94

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



82
83
84
85
86
87
88
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 82

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

  then_expression.each_step(&block)

  self
end

#error?Boolean

Returns:

  • (Boolean)


71
72
73
74
75
76
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 71

def error?
  return false if condition_expression.failure?
  return true if condition_expression.error?

  then_expression.error?
end

#failure?Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 61

def failure?
  return true if condition_expression.failure?
  return false if condition_expression.error?

  then_expression.failure?
end

#if?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 120

def if?
  true
end

#inspectString

Returns:

  • (String)


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

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

#organizerConvenientService::Service



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

def organizer
  condition_expression.organizer
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)


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

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

#to_argumentsConvenientService::Support::Arguments



140
141
142
# File 'lib/convenient_service/service/plugins/can_have_connected_steps/entities/expressions/if.rb', line 140

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

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



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

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