ccp 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,7 @@ module Ccp
7
7
  autoload :RuntimeArgs , 'ccp/commands/runtime_args'
8
8
  autoload :Commentable , 'ccp/commands/commentable'
9
9
  autoload :Core , 'ccp/commands/core'
10
+ autoload :Base , 'ccp/commands/base'
10
11
  autoload :Resolvable , 'ccp/commands/resolvable'
11
12
  end
12
13
  end
@@ -0,0 +1,13 @@
1
+ module Ccp
2
+ module Commands
3
+ class Base
4
+ include Ccp::Commands::Core
5
+
6
+ attr_reader :args
7
+
8
+ def initialize(*args)
9
+ @args = args
10
+ end
11
+ end
12
+ end
13
+ end
@@ -31,7 +31,7 @@ module Ccp
31
31
 
32
32
  def append_command(klass, *args, &block)
33
33
  klass = resolve(klass)
34
- if commands.find{|cc| cc.klass == klass}
34
+ if commands.find{|cc| cc.klass == klass and cc.args == args}
35
35
  # ignore: already added
36
36
  else
37
37
  commands << CommandClass.new(klass, args, block)
@@ -1,3 +1,3 @@
1
1
  module Ccp
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -0,0 +1,20 @@
1
+ require "spec_helper"
2
+
3
+ describe Ccp::Commands::Base do
4
+ describe "#initialize" do
5
+ it "should accept *args" do
6
+ lambda {
7
+ Ccp::Commands::Base.new
8
+ Ccp::Commands::Base.new(1)
9
+ Ccp::Commands::Base.new(:a, "str", {1=>[]})
10
+ }.should_not raise_error
11
+ end
12
+ end
13
+
14
+ describe "#args" do
15
+ it "should return args" do
16
+ cmd = Ccp::Commands::Base.new("data.db", :adapter=>"sqlite", :type=>"kvs")
17
+ cmd.args.should == ["data.db", {:adapter=>"sqlite", :type=>"kvs"}]
18
+ end
19
+ end
20
+ end
@@ -26,6 +26,45 @@ describe Ccp::Commands::Composite do
26
26
  "Program#after"]
27
27
  end
28
28
  end
29
+
30
+ describe ".command" do
31
+ ArgedCmd = Struct.new(:a,:b,:c) {
32
+ include Ccp::Commands::Core
33
+ def execute
34
+ data[:args] = [a,b,c]
35
+ end
36
+ }
37
+
38
+ it "should pass given args to initializer" do
39
+ parent = Class.new { include Ccp::Commands::Composite
40
+ command ArgedCmd
41
+ }.new
42
+ parent.execute
43
+ parent.data[:args].should == [nil,nil,nil]
44
+
45
+ parent = Class.new { include Ccp::Commands::Composite
46
+ command ArgedCmd, 1, "x"
47
+ }.new
48
+ parent.execute
49
+ parent.data[:args].should == [1, "x", nil]
50
+ end
51
+
52
+ it "should ignore same commands" do
53
+ composite = Class.new { include Ccp::Commands::Composite
54
+ command ArgedCmd
55
+ command ArgedCmd
56
+ }
57
+ composite.commands.size.should == 1
58
+ end
59
+
60
+ it "should distinct command's args" do
61
+ composite = Class.new { include Ccp::Commands::Composite
62
+ command ArgedCmd
63
+ command ArgedCmd, 1
64
+ }
65
+ composite.commands.size.should == 2
66
+ end
67
+ end
29
68
  end
30
69
 
31
70
  describe "Ccp::Commands::Composite(nested)" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ccp
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - maiha
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-02-14 00:00:00 +09:00
18
+ date: 2012-03-09 00:00:00 +09:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -82,6 +82,7 @@ files:
82
82
  - lib/ccp.rb
83
83
  - lib/ccp/colorize.rb
84
84
  - lib/ccp/commands.rb
85
+ - lib/ccp/commands/base.rb
85
86
  - lib/ccp/commands/command_not_found.rb
86
87
  - lib/ccp/commands/commentable.rb
87
88
  - lib/ccp/commands/composite.rb
@@ -99,6 +100,7 @@ files:
99
100
  - lib/ccp/receivers/none.rb
100
101
  - lib/ccp/receivers/profileable.rb
101
102
  - lib/ccp/version.rb
103
+ - spec/commands_base_spec.rb
102
104
  - spec/commands_composite_spec.rb
103
105
  - spec/commands_core_spec.rb
104
106
  - spec/data_spec.rb