Class: Browserctl::WorkflowContext

Inherits:
Object
  • Object
show all
Defined in:
lib/browserctl/workflow.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params, client) ⇒ WorkflowContext

Returns a new instance of WorkflowContext.



16
17
18
19
20
# File 'lib/browserctl/workflow.rb', line 16

def initialize(params, client)
  @params = params
  @client = client
  @_store = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



30
31
32
33
34
# File 'lib/browserctl/workflow.rb', line 30

def method_missing(name, *args)
  return @params[name] if @params.key?(name)

  super
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



14
15
16
# File 'lib/browserctl/workflow.rb', line 14

def client
  @client
end

Instance Method Details

#assert(condition, msg = "assertion failed") ⇒ Object

Raises:



64
65
66
# File 'lib/browserctl/workflow.rb', line 64

def assert(condition, msg = "assertion failed")
  raise WorkflowError, msg unless condition
end

#close_page(page_name) ⇒ Object

Raises:



51
52
53
54
55
56
# File 'lib/browserctl/workflow.rb', line 51

def close_page(page_name)
  res = @client.close_page(page_name.to_s)
  raise WorkflowError, res[:error] if res[:error]

  res
end

#fetch(key) ⇒ Object



26
27
28
# File 'lib/browserctl/workflow.rb', line 26

def fetch(key)
  @_store.fetch(key) { raise KeyError, "no value stored for key #{key.inspect}" }
end

#invoke(workflow_name, **override_params) ⇒ Object



58
59
60
61
62
# File 'lib/browserctl/workflow.rb', line 58

def invoke(workflow_name, **override_params)
  name = workflow_name.to_s
  guard_circular!(name)
  track_invoke(name) { run_nested(workflow_name, **override_params) }
end

#open_page(page_name, url: nil) ⇒ Object

Raises:



44
45
46
47
48
49
# File 'lib/browserctl/workflow.rb', line 44

def open_page(page_name, url: nil)
  res = @client.open_page(page_name.to_s, url: url)
  raise WorkflowError, res[:error] if res[:error]

  res
end

#page(name) ⇒ Object



40
41
42
# File 'lib/browserctl/workflow.rb', line 40

def page(name)
  PageProxy.new(name.to_s, @client)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/browserctl/workflow.rb', line 36

def respond_to_missing?(name, include_private = false)
  @params.key?(name) || super
end

#store(key, value) ⇒ Object



22
23
24
# File 'lib/browserctl/workflow.rb', line 22

def store(key, value)
  @_store[key] = value
end