class Rookout::Processor::Paths::Canopy::Opt

Attributes

level[R]

Public Class Methods

new(opt) click to toggle source
# File lib/rookout/processor/paths/canopy/markers.rb, line 138
def initialize opt
  @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

Public Instance Methods

check_result(result, first_obj, second_obj) click to toggle source
# File lib/rookout/processor/paths/canopy/markers.rb, line 157
def check_result result, first_obj, second_obj
  return unless [true, false].include? result
  if result
    return
  end

  unless first_obj.nil?
    raise Exceptions::RookNonPrimitiveObjectType, first_obj.class.to_s unless
      PRIMITIVES.include? first_obj.class
  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) click to toggle source
# File lib/rookout/processor/paths/canopy/markers.rb, line 173
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

Private Instance Methods

decapsulate_item(item) click to toggle source
# File lib/rookout/processor/paths/canopy/markers.rb, line 199
def decapsulate_item item
  return item.obj.obj if item.is_a? NamespaceResult
  item.obj
end