Class: Rookout::Processor::Paths::Canopy::Opt

Inherits:
Marker
  • Object
show all
Defined in:
lib/rookout/processor/paths/canopy/markers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opt) ⇒ Opt

Returns a new instance of Opt.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/rookout/processor/paths/canopy/markers.rb', line 147

def initialize opt
  super()

  @opt = opt
  @level = nil

  # Some ops have alternatives we convert back to standard
  @opt = OPS_ALTERNATIVES[@opt.upcase] if OPS_ALTERNATIVES.key? @opt.upcase

  ALL_LEVELS.each_with_index do |ops, index|
    if ops.include? @opt
      @level = index
      break
    end
  end

  raise Exceptions::RookInvalidArithmeticPath, @opt if @level.nil?
end

Instance Attribute Details

#levelObject (readonly)

Returns the value of attribute level.



166
167
168
# File 'lib/rookout/processor/paths/canopy/markers.rb', line 166

def level
  @level
end

Instance Method Details

#check_result(result, first_obj, second_obj) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/rookout/processor/paths/canopy/markers.rb', line 168

def check_result result, first_obj, second_obj
  return unless [true, false].include? result
  if result
    return
  end

  if !first_obj.nil? && !(PRIMITIVES.include? first_obj.class)
    raise Exceptions::RookNonPrimitiveObjectType, first_obj.class.to_s
  end

  return if second_obj.nil?
  raise Exceptions::RookNonPrimitiveObjectType, second_obj.class.to_s unless
    PRIMITIVES.include? second_obj.class
end

#execute_operation(first, second) ⇒ Object



183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/rookout/processor/paths/canopy/markers.rb', line 183

def execute_operation first, second
  # Remove  wrapping of objects as needed
  first_obj = decapsulate_item first
  second_obj = decapsulate_item second

  result = nil
  begin
    result = OPS_FUNCTIONS[@opt].call first_obj, second_obj
  rescue StandardError => e
    raise Exceptions::RookExceptionEvaluationFailed.new "", e
  end

  check_result result, first_obj, second_obj

  # If we don't have a result
  if result.nil?
    # Verify objects are primitives
    raise Exceptions::RookNonPrimitiveObjectType, a.text unless PRIMITIVES.include? first_obj.class
    raise Exceptions::RookNonPrimitiveObjectType, b.text unless PRIMITIVES.include? second_obj.class
  end

  ObjectMarker.new result.to_s, result
end