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.



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

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



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

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