Class: ZWRouter
- Inherits:
-
Object
- Object
- ZWRouter
- Defined in:
- lib/wurst/resource.rb
Instance Attribute Summary collapse
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Instance Method Summary collapse
- #has_route?(route_name) ⇒ Boolean
-
#initialize ⇒ ZWRouter
constructor
A new instance of ZWRouter.
- #method_missing(method_name, *args, &block) ⇒ Object
- #switch(new_val = true) ⇒ Object
Constructor Details
#initialize ⇒ ZWRouter
Returns a new instance of ZWRouter.
8 9 10 11 |
# File 'lib/wurst/resource.rb', line 8 def initialize @routes = {} @active = false end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/wurst/resource.rb', line 18 def method_missing method_name, *args, &block if [:create, :read, :update, :destroy, :index].include? method_name if @active @routes[method_name].call args else @routes[method_name] = block end else super end end |
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
6 7 8 |
# File 'lib/wurst/resource.rb', line 6 def routes @routes end |
Instance Method Details
#has_route?(route_name) ⇒ Boolean
12 13 14 |
# File 'lib/wurst/resource.rb', line 12 def has_route? route_name @routes.has_key? route_name end |
#switch(new_val = true) ⇒ Object
15 16 17 |
# File 'lib/wurst/resource.rb', line 15 def switch new_val = true @active = new_val end |