Class: WebFunction::Promise

Inherits:
Object
  • Object
show all
Defined in:
lib/web_function/promise.rb

Instance Method Summary collapse

Constructor Details

#initialize(pipeline, path) ⇒ Promise

Returns a new instance of Promise.



3
4
5
6
# File 'lib/web_function/promise.rb', line 3

def initialize(pipeline, path)
  @pipeline = pipeline
  @path = path
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/web_function/promise.rb', line 31

def method_missing(name, *args)
  if block_given? || args.any?
    super
  end

  mutate("#{@path}.#{name}")
end

Instance Method Details

#[](key) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/web_function/promise.rb', line 20

def [](key)
  case key
  when String
    mutate("#{@path}[\"#{key}\"]")
  when Integer
    mutate("#{@path}[#{key}]")
  else
    raise ArgumentError
  end
end

#resolveObject



16
17
18
# File 'lib/web_function/promise.rb', line 16

def resolve
  @pipeline.execute(returns: :last)
end

#to_json(*args) ⇒ Object



12
13
14
# File 'lib/web_function/promise.rb', line 12

def to_json(*args)
  @path.to_json(*args)
end

#to_sObject



8
9
10
# File 'lib/web_function/promise.rb', line 8

def to_s
  @path
end