Class: Buttons::Button

Inherits:
Object
  • Object
show all
Defined in:
lib/buttons/button.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ Button

Returns a new instance of Button.



7
8
9
# File 'lib/buttons/button.rb', line 7

def initialize(request)
  @request = request
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request.



5
6
7
# File 'lib/buttons/button.rb', line 5

def request
  @request
end

Class Method Details

.argument_listObject



41
42
43
# File 'lib/buttons/button.rb', line 41

def argument_list
  @argument_list ||= {}
end

.get(*names) ⇒ Object



49
50
51
52
53
# File 'lib/buttons/button.rb', line 49

def get(*names)
  names.each do |name|
    add_route(:get, name)
  end
end

.inherited(base) ⇒ Object



20
21
22
23
# File 'lib/buttons/button.rb', line 20

def inherited(base)        
  Buttons.app.add_route(:get, "/#{base.namespace}.js",
    :button => base, :method => :to_js)
end

.js_functionsObject



37
38
39
# File 'lib/buttons/button.rb', line 37

def js_functions
  @js_functions ||= []
end

.method_added(name) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/buttons/button.rb', line 25

def method_added(name)
  routes.each do |http_method, methods|
    if methods.include?(name)
      setup_route(http_method, instance_method(name))
    end
  end
end

.namespaceObject



33
34
35
# File 'lib/buttons/button.rb', line 33

def namespace
  self.to_s.debuttonize
end

.post(*names) ⇒ Object



55
56
57
58
59
# File 'lib/buttons/button.rb', line 55

def post(*names)
  names.each do |name|
    add_route(:post, name)
  end
end

.routesObject



45
46
47
# File 'lib/buttons/button.rb', line 45

def routes
  @routes ||= { }
end

.to_jsObject



61
62
63
# File 'lib/buttons/button.rb', line 61

def to_js
  Buttons::Javascript::JsGenerator.new(self).to_js
end

Instance Method Details

#call_method(method_name) ⇒ Object



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

def call_method(method_name)      
  send(method_name, *create_method_args(method_name))
end

#to_jsObject



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

def to_js
  self.class.to_js
end