Class: Delorean::BaseModule::NodeCall

Inherits:
Struct
  • Object
show all
Defined in:
lib/delorean/base.rb

Overview

_e is used by Marty promise_jobs to pass promise-related information

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_eObject

Returns the value of attribute _e

Returns:

  • (Object)

    the current value of _e



29
30
31
# File 'lib/delorean/base.rb', line 29

def _e
  @_e
end

#engineObject

Returns the value of attribute engine

Returns:

  • (Object)

    the current value of engine



29
30
31
# File 'lib/delorean/base.rb', line 29

def engine
  @engine
end

#nodeObject

Returns the value of attribute node

Returns:

  • (Object)

    the current value of node



29
30
31
# File 'lib/delorean/base.rb', line 29

def node
  @node
end

#paramsObject

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



29
30
31
# File 'lib/delorean/base.rb', line 29

def params
  @params
end

Instance Method Details

#%(args) ⇒ Object

FIXME: % should also support string as args



71
72
73
74
75
# File 'lib/delorean/base.rb', line 71

def %(args)
  raise 'non-array arg to %' unless args.is_a?(Array)

  engine.eval_to_hash(node, args, cloned_params)
end

#+(args) ⇒ Object

add new arguments, results in a new NodeCall



78
79
80
81
82
# File 'lib/delorean/base.rb', line 78

def +(args)
  raise 'bad arg to +' unless args.is_a?(Hash)

  NodeCall.new(_e, engine, node, params.merge(args))
end

#/(args) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/delorean/base.rb', line 57

def /(args)
  case args
  when Array
    engine.eval_to_hash(node, args, cloned_params)
  when String
    evaluate(args)
  else
    raise 'non-array/string arg to /'
  end
rescue StandardError => exc
  Delorean::Engine.grok_runtime_exception(exc)
end

#_evaluate_with_cache(attr) ⇒ Object



46
47
48
49
50
51
52
53
54
55
# File 'lib/delorean/base.rb', line 46

def _evaluate_with_cache(attr)
  ::Delorean::Cache.with_cache(
    klass: node,
    method: attr,
    mutable_params: cloned_params,
    params: params
  ) do
    engine.evaluate(node, attr, cloned_params)
  end
end

#cloned_paramsObject



30
31
32
33
34
35
36
# File 'lib/delorean/base.rb', line 30

def cloned_params
  # FIXME: evaluate() modifies params! => need to clone it.
  # This is pretty awful.  NOTE: can't sanitize params as Marty
  # patches NodeCall and modifies params to send _parent_id.
  # This whole thing needs to be redone.
  @cloned_params ||= Hash[params]
end

#evaluate(attr) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/delorean/base.rb', line 38

def evaluate(attr)
  if node.respond_to?(NODE_CACHE_ARG) && node.send(NODE_CACHE_ARG, _e)
    return _evaluate_with_cache(attr)
  end

  engine.evaluate(node, attr, cloned_params)
end