mvcli 0.0.12 → 0.0.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6824dd7970a2422da62ebac790697827af7493b
4
- data.tar.gz: e7e26c779892ddbc361db8e69d78e4c88f3a2c5f
3
+ metadata.gz: c8df3bbd6ac8b26f4a48b1ed2d9c67a8ef4a8616
4
+ data.tar.gz: caff046276e71a1e374b6f58941e5f6a25422c78
5
5
  SHA512:
6
- metadata.gz: 74431de1c5cb00bc2f51d87a10fe407696b8449a1071a28f16039f8ece375ec05ab360eee2a49e819b9b40f1c26fb7af0ebfc9a9a54c7af025c5a436bc45d705
7
- data.tar.gz: 82af2de453863e0f74871bb61a83db8305e5a0bb638c805e2443c42dbca506399a53e2ec9bb80f428af8dc9b0e85358f3b1c14e16f851c23f3e04239b514021e
6
+ metadata.gz: 72f2bfbd5958be1c910e1fe92d3259a43112e64f83563b837e76b6df153ee27f665406e8b98d336c3e737e8860dd08275d87717dd3112488774b3e04bd54289a
7
+ data.tar.gz: 70fd38e776ff6c3e8c3ad4b6b49efb2f96143366eadadd4416577a45ceb51d07c0cc009f4ba82141eb822b1966fc27c7d747d246080ef5ad7bd80b7bb34de4e0
@@ -10,6 +10,11 @@ module MVCLI
10
10
  def initialize(actions = nil)
11
11
  @actions = actions || Map.new
12
12
  @routes = []
13
+ @macros = []
14
+ end
15
+
16
+ def macro(options)
17
+ @macros.push Macro.new options
13
18
  end
14
19
 
15
20
  def match(options)
@@ -19,22 +24,35 @@ module MVCLI
19
24
  end
20
25
 
21
26
  def call(command)
27
+ argv = @macros.reduce(command.argv) do |args, macro|
28
+ macro.expand args
29
+ end
22
30
  @routes.each do |route|
23
- if match = route.match(command)
31
+ if match = route.match(argv)
24
32
  return match.call command
25
33
  end
26
34
  end
27
35
  fail RoutingError, "no route matches '#{command.argv.join ' '}'"
28
36
  end
29
37
 
38
+ class Macro
39
+ def initialize(options)
40
+ @pattern, @expansion = options.first
41
+ end
42
+
43
+ def expand(argv)
44
+ argv.join(" ").gsub(@pattern, @expansion).split /\s+/
45
+ end
46
+ end
47
+
30
48
  class Route
31
49
  def initialize(pattern, actions, action, options = {})
32
50
  @pattern = Pattern.new pattern.to_s
33
51
  @actions, @action, @options = actions, action, options
34
52
  end
35
53
 
36
- def match(command)
37
- argv = MVCLI::Argv.new command.argv
54
+ def match(argv)
55
+ argv = MVCLI::Argv.new argv
38
56
  match = @pattern.match(argv.arguments)
39
57
  if match.matches?
40
58
  proc do |command|
@@ -1,3 +1,3 @@
1
1
  module MVCLI
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
@@ -45,6 +45,13 @@ describe "MVCLI::Router" do
45
45
  And {@bindings[:id].should eql '6'}
46
46
  end
47
47
 
48
+ context "with macros" do
49
+ Given { router.macro /(-h|--help) (.*)/ => "help \\2" }
50
+ Given { router.match "help me" => "help#me"}
51
+ When { invoke "--help me" }
52
+ Then { @action.should eql 'help#me' }
53
+ end
54
+
48
55
  def invoke(route = '')
49
56
  router.call mock(:Command, :argv => route.split(/\s+/))
50
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mvcli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.12
4
+ version: 0.0.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Lowell