Class: Twke::Routes::RoutePrefix
- Inherits:
-
Object
- Object
- Twke::Routes::RoutePrefix
- Defined in:
- lib/twke/routes.rb
Instance Method Summary collapse
-
#cmd(&blk) ⇒ Object
Run a raw command and the connection scope level.
-
#initialize(str = nil) ⇒ RoutePrefix
constructor
A new instance of RoutePrefix.
- #method_missing(name, *opts, &blk) ⇒ Object
- #route(trigger, *opts, &blk) ⇒ Object
Constructor Details
#initialize(str = nil) ⇒ RoutePrefix
Returns a new instance of RoutePrefix.
4 5 6 7 |
# File 'lib/twke/routes.rb', line 4 def initialize(str = nil) @levels = [] @levels.push(str) if str end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *opts, &blk) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/twke/routes.rb', line 29 def method_missing(name, *opts, &blk) if no_prefix?(*opts) # If they requested no prefix, save the current prefix # and execute the block starting with the current prefix save_levels = @levels.dup @levels = [name] yield @levels = save_levels else @levels.push(name) yield @levels.pop end end |
Instance Method Details
#cmd(&blk) ⇒ Object
Run a raw command and the connection scope level
25 26 27 |
# File 'lib/twke/routes.rb', line 25 def cmd(&blk) Routes.cmd(&blk) end |
#route(trigger, *opts, &blk) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/twke/routes.rb', line 9 def route(trigger, *opts, &blk) if trigger.class == Regexp if prefix.length > 0 && !no_prefix?(*opts) trigger = Regexp.new("#{prefix} #{trigger.to_s}") end Routes.add(trigger, *opts, &blk) else # Send trigger as a prefix self.send(trigger, *opts) do Routes.add(prefix, *opts, &blk) end end end |