Class: Buttons::Javascript::JsFunction

Inherits:
JsVar
  • Object
show all
Defined in:
lib/buttons/javascript/js_function.rb

Instance Attribute Summary collapse

Attributes inherited from JsVar

#ruby_name

Instance Method Summary collapse

Methods inherited from JsVar

#to_s

Constructor Details

#initialize(name, http_method, url, args) ⇒ JsFunction

Returns a new instance of JsFunction.



6
7
8
9
10
11
12
# File 'lib/buttons/javascript/js_function.rb', line 6

def initialize(name, http_method, url, args)
  super(name)

  @http_method = http_method
  @url = url
  @args = args.map { |arg| JsArg.new(arg) }
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



4
5
6
# File 'lib/buttons/javascript/js_function.rb', line 4

def args
  @args
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/buttons/javascript/js_function.rb', line 4

def name
  @name
end

Instance Method Details

#to_js(namespace = 'this') ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/buttons/javascript/js_function.rb', line 14

def to_js(namespace = 'this')
  %Q[
    #{namespace}.#{name} = function (#{args_to_param_list}, _ajaxOptions) {
      #{args_to_defaults}
      #{assign_args_to_js_object}
      #{ajax_call}
    };
  ].strip_whitespace        
end