ppl 1.13.0 → 1.14.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -44,6 +44,12 @@ class Ppl::Application::Bootstrap
44
44
  return config
45
45
  end
46
46
 
47
+ def execute_command
48
+ command = Ppl::Command::Execute.new(nil, nil, nil)
49
+ command.storage = storage_adapter
50
+ command
51
+ end
52
+
47
53
  def git_commands
48
54
  [
49
55
  Ppl::Command::Execute.new("pull", "git pull", "Execute 'git pull' in the address book directory"),
@@ -66,6 +72,7 @@ class Ppl::Application::Bootstrap
66
72
  router = Ppl::Application::Router.new(command_suite)
67
73
  router.aliases = configuration.aliases
68
74
  router.default = "help"
75
+ router.execute_command = execute_command
69
76
  return router
70
77
  end
71
78
 
@@ -3,6 +3,7 @@ class Ppl::Application::Router
3
3
 
4
4
  attr_accessor :aliases
5
5
  attr_accessor :default
6
+ attr_accessor :execute_command
6
7
 
7
8
  def initialize(command_suite)
8
9
  @command_suite = command_suite
@@ -12,7 +13,11 @@ class Ppl::Application::Router
12
13
  def route(argument)
13
14
  command = @command_suite.find_command(argument)
14
15
  if command.nil? && @aliases.has_key?(argument)
15
- command = @command_suite.find_command(@aliases[argument])
16
+ if is_bang_alias?(argument)
17
+ command = create_execute_command(argument)
18
+ else
19
+ command = @command_suite.find_command(@aliases[argument])
20
+ end
16
21
  end
17
22
  if command.nil? && !@default.nil?
18
23
  command = @command_suite.find_command(@default)
@@ -20,5 +25,18 @@ class Ppl::Application::Router
20
25
  return command
21
26
  end
22
27
 
28
+
29
+ private
30
+
31
+ def is_bang_alias?(key)
32
+ @aliases[key].match(/^!/)
33
+ end
34
+
35
+ def create_execute_command(key)
36
+ @execute_command.name = key
37
+ @execute_command.command = @aliases[key][1..-1]
38
+ @execute_command
39
+ end
40
+
23
41
  end
24
42
 
@@ -1,6 +1,8 @@
1
1
 
2
2
  class Ppl::Command::Execute < Ppl::Application::Command
3
3
 
4
+ attr_accessor :command
5
+
4
6
  def initialize(name, command, description)
5
7
  @name = name
6
8
  @command = command
data/lib/ppl.rb CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Ppl
3
3
 
4
- Version = "1.13.0"
4
+ Version = "1.14.0"
5
5
 
6
6
  module Adapter
7
7
  end
data/ppl.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
  Gem::Specification.new do |spec|
3
3
 
4
4
  spec.name = "ppl"
5
- spec.version = "1.13.0"
5
+ spec.version = "1.14.0"
6
6
  spec.date = "2013-02-17"
7
7
 
8
8
  spec.required_ruby_version = ">= 1.9.3"
@@ -5,6 +5,9 @@ describe Ppl::Application::Router do
5
5
  @suite = Ppl::Application::CommandSuite.new
6
6
  @router = Ppl::Application::Router.new(@suite)
7
7
 
8
+ @execute = double(Ppl::Command::Execute)
9
+ @router.execute_command = @execute
10
+
8
11
  @cmd_one = Ppl::Application::Command.new
9
12
  @cmd_one.name = "one"
10
13
 
@@ -42,6 +45,13 @@ describe Ppl::Application::Router do
42
45
  @router.route("t").should be @cmd_two
43
46
  end
44
47
 
48
+ it "should return a Ppl::Command::Execute if the input matches a bang alias" do
49
+ @execute.should_receive(:name=).with("t")
50
+ @execute.should_receive(:command=).with("two")
51
+ @router.aliases = {"t" => "!two"}
52
+ @router.route("t").should be @execute
53
+ end
54
+
45
55
  end
46
56
 
47
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ppl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.13.0
4
+ version: 1.14.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: