Class: Buttons::Javascript::JsArg

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

Instance Attribute Summary collapse

Attributes inherited from JsVar

#ruby_name

Instance Method Summary collapse

Methods inherited from JsVar

#to_s

Constructor Details

#initialize(var) ⇒ JsArg

Returns a new instance of JsArg.



6
7
8
9
# File 'lib/buttons/javascript/js_arg.rb', line 6

def initialize(var)
  @var = var
  super(@var.name)        
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object



11
12
13
# File 'lib/buttons/javascript/js_arg.rb', line 11

def method_missing(*args, &block)
  @var.send(*args, &block)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#defaultObject



15
16
17
# File 'lib/buttons/javascript/js_arg.rb', line 15

def default
  @var.default.to_json
end

#to_default(index) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/buttons/javascript/js_arg.rb', line 19

def to_default(index)
  if optional?
    %Q[
      if (#{name} === undefined) {
        #{name} = #{default};
      }
    ]
  end        
end