Class: Capybara::AsyncRunner::Env

Inherits:
Object
  • Object
show all
Defined in:
lib/capybara/async_runner/env.rb

Overview

Internal class for building environment for rendering .js.erb code

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uuid, data, responders) ⇒ Env

For responders:

Parameters:

  • uuid (String)

    just a uuid of running command

  • data (Hash)

    data that is available in .erb through <%= data %>

  • responders (Hash<Symbol, Hash>)

    mapping method_name => options

See Also:



11
12
13
14
15
# File 'lib/capybara/async_runner/env.rb', line 11

def initialize(uuid, data, responders)
  @uuid = uuid
  @data = data
  @responders = responders
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object

Delegates a method to responder

Examples:

<%= responder1(js[:var1]) %>

See Also:



39
40
41
42
43
44
45
# File 'lib/capybara/async_runner/env.rb', line 39

def method_missing(method_name, *args)
  if responders.include?(method_name)
    response_method_for(method_name, *args)
  else
    super
  end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



16
17
18
# File 'lib/capybara/async_runner/env.rb', line 16

def data
  @data
end

#respondersObject (readonly)

Returns the value of attribute responders.



16
17
18
# File 'lib/capybara/async_runner/env.rb', line 16

def responders
  @responders
end

#uuidObject (readonly)

Returns the value of attribute uuid.



16
17
18
# File 'lib/capybara/async_runner/env.rb', line 16

def uuid
  @uuid
end

Instance Method Details

#js_environmentObject Also known as: js

Returns a js environment that can be used for fetching data from the code on-the-fly

Examples:

# spec/support/async_runner/templates/command1.js.erb
var jsLocal = 123;
<%= done(js[:jsLocal] %>


25
26
27
28
29
# File 'lib/capybara/async_runner/env.rb', line 25

def js_environment
  Hash.new do |h, k|
    k.to_s
  end
end

#local_bindingBinding

Returns local binding that is used for rendering (ERB.new(template).result(binding))

Returns:

  • (Binding)


56
57
58
# File 'lib/capybara/async_runner/env.rb', line 56

def local_binding
  binding
end

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

Returns:

  • (Boolean)


48
49
50
# File 'lib/capybara/async_runner/env.rb', line 48

def respond_to_missing?(method_name, include_private = false)
  super || responders.include?(method_name)
end