Class: Delorean::BaseModule::NodeCall

Inherits:
Object
  • Object
show all
Defined in:
lib/marty/monkey.rb

Overview

Patch Delorean to work with promises

Instance Method Summary collapse

Constructor Details

#initialize(_e, engine, node, params) ⇒ NodeCall

Returns a new instance of NodeCall.



28
29
30
31
32
33
34
35
# File 'lib/marty/monkey.rb', line 28

def initialize(_e, engine, node, params)
  super

  # If call has a promise_id (i.e. is from a promise) then that's
  # our parent.  Otherwise, we use its parent as our parent.
  params[:_parent_id] = _e[:_promise_id] || _e[:_parent_id]
  params[:_user_id]   = _e[:_user_id]    || Mcfly.whodunnit.try(:id)
end

Instance Method Details

#|(args) ⇒ Object

Monkey-patch ‘|’ method for Delorean NodeCall to create promise jobs and return promise proxy objects.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/marty/monkey.rb', line 43

def |(args)
  if args.is_a?(String)
    attr = args
    args = [attr]
  else
    raise 'bad arg to %' unless args.is_a?(Array)

    attr = nil
  end
  script, tag = engine.module_name, engine.sset.tag
  nn = node.is_a?(Class) ? node.name : node.to_s
  begin
    # make sure params is serialzable before starting a Job
    JSON.dump(params)
  rescue StandardError => e
    raise "non-serializable parameters: #{params} #{e}"
  end

  Marty::Promises::Delorean::Create.call(
    params: params,
    script: script,
    node_name: nn,
    attr: attr,
    args: args,
    tag: tag
  )
end