Class: MVCLI::Router::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/mvcli/router.rb

Instance Method Summary collapse

Constructor Details

#initialize(pattern, actions, action, options = {}) ⇒ Route

Returns a new instance of Route.



30
31
32
33
# File 'lib/mvcli/router.rb', line 30

def initialize(pattern, actions, action, options = {})
  @pattern = Pattern.new pattern.to_s
  @actions, @action, @options = actions, action, options
end

Instance Method Details

#match(command) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/mvcli/router.rb', line 35

def match(command)
  match = @pattern.match(command.argv)
  if match.matches?
    proc do |command|
      action = @actions[@action] or fail "no action found for #{@action}"
      action.call command, match.bindings
    end
  end
end