Class: VersatileRJS::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/versatile_rjs/proxy.rb,
lib/versatile_rjs/proxy/jquery.rb,
lib/versatile_rjs/proxy/each_proxy.rb,
lib/versatile_rjs/proxy/selectable.rb,
lib/versatile_rjs/proxy/element_proxy.rb,
lib/versatile_rjs/proxy/selector_proxy.rb,
lib/versatile_rjs/proxy/expression_proxy.rb,
lib/versatile_rjs/proxy/default_responder.rb,
lib/versatile_rjs/proxy/element_set_proxy.rb,
lib/versatile_rjs/proxy/jquery/each_proxy.rb,
lib/versatile_rjs/proxy/jquery/selectable.rb,
lib/versatile_rjs/proxy/jquery/element_set.rb,
lib/versatile_rjs/proxy/element_by_id_proxy.rb,
lib/versatile_rjs/proxy/framework_dependent.rb,
lib/versatile_rjs/proxy/jquery/element_proxy.rb,
lib/versatile_rjs/proxy/jquery/selector_proxy.rb,
lib/versatile_rjs/proxy/jquery/element_set_proxy.rb,
lib/versatile_rjs/proxy/jquery/element_by_id_proxy.rb

Direct Known Subclasses

EachProxy, ElementProxy, ElementSetProxy

Defined Under Namespace

Modules: DefaultResponder, ElementByIdProxy, FrameworkDependent, Jquery, Selectable, SelectorProxy Classes: EachProxy, ElementProxy, ElementSetProxy, ExpressionProxy

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, statement) ⇒ Proxy

Returns a new instance of Proxy.



12
13
14
15
# File 'lib/versatile_rjs/proxy.rb', line 12

def initialize(page, statement)
  @page = page
  @statement = statement
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



8
9
10
# File 'lib/versatile_rjs/proxy.rb', line 8

def method_missing(method, *args)
  page.append_statement call(method, *args)
end

Instance Attribute Details

#container=(value) ⇒ Object

Sets the attribute container

Parameters:

  • value

    the value to set the attribute container to.



5
6
7
# File 'lib/versatile_rjs/proxy.rb', line 5

def container=(value)
  @container = value
end

#index=(value) ⇒ Object

Sets the attribute index

Parameters:

  • value

    the value to set the attribute index to.



5
6
7
# File 'lib/versatile_rjs/proxy.rb', line 5

def index=(value)
  @index = value
end

Instance Method Details

#call(method, *arguments) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/versatile_rjs/proxy.rb', line 17

def call(method, *arguments)
  method = method.to_s.camelcase(:lower)
  script =
    if method =~ /(.*)=$/
      "#{statement}.#{$1} = #{arguments.first.to_json}"
    else
      "#{statement}.#{method}(#{arguments.map(&:to_json).join(', ')})"
    end
  ActiveSupport::JSON::Variable.new script
end

#to_jsonObject Also known as: to_s



28
29
30
# File 'lib/versatile_rjs/proxy.rb', line 28

def to_json
  ActiveSupport::JSON::Variable.new(statement)
end