ccp 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -64,8 +64,8 @@ It is too hard to see data dependencies especially about instance variables.
64
64
  class FetchData # 1. SRP
65
65
  include Ccp::Commands::Core
66
66
 
67
- # {pre,post} methods can be used like Design By Contract
68
- def post
67
+ # {before,after} methods can be used like Design By Contract
68
+ def after
69
69
  data.check(:fetched, {Symbol => [Float]}) # 2. Typed Variables
70
70
  end
71
71
 
@@ -84,7 +84,7 @@ in each scopes, and can share variables only via data object.
84
84
 
85
85
  So you can easily refactor or replace FetchData unit
86
86
  because there are no implicit instance variable dependencies
87
- and futhermore all depencenies would be explicitly declared in "pre","post" method.
87
+ and futhermore all depencenies would be explicitly declared in "before","after" method.
88
88
 
89
89
  === execute
90
90
 
@@ -57,13 +57,6 @@ module Ccp
57
57
  end
58
58
  end
59
59
 
60
- def benchmark
61
- before
62
- super
63
- after
64
- return true
65
- end
66
-
67
60
  def receiver
68
61
  @receiver.must(Receivers::Base)
69
62
  end
@@ -72,14 +65,10 @@ module Ccp
72
65
  @receiver = value.must(Receivers::Base)
73
66
  end
74
67
 
75
- private
76
- def before
77
- end
78
-
79
- def after
80
- show_profiles if data?(:profile)
81
- show_comments if data?(:comment)
82
- end
68
+ def after
69
+ show_profiles if data?(:profile)
70
+ show_comments if data?(:comment)
71
+ end
83
72
  end
84
73
  end
85
74
  end
@@ -16,9 +16,9 @@ module Ccp
16
16
 
17
17
  def profile(target, method)
18
18
  start = Time.new
19
- target.__send__(:pre) if target.respond_to?(:pre)
19
+ target.__send__(:before) if target.respond_to?(:before)
20
20
  target.__send__(method)
21
- target.__send__(:post) if target.respond_to?(:post)
21
+ target.__send__(:after) if target.respond_to?(:after)
22
22
 
23
23
  case target
24
24
  when Ccp::Commands::Composite
data/lib/ccp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ccp
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -2,66 +2,66 @@ require "spec_helper"
2
2
 
3
3
  describe Ccp::Commands::Composite do
4
4
  describe "#execute" do
5
- it "should call its execute and sub commands's {pre,execute,post} in declared order" do
5
+ it "should call its execute and sub commands's {before,execute,after} in declared order" do
6
6
  c = Program.new
7
7
  c.data[:breadcrumbs] = []
8
8
  c.execute
9
9
  c.data[:breadcrumbs].should ==
10
- ["Cmd1#pre", "Cmd1#execute", "Cmd1#post",
11
- "Cmd2#pre", "Cmd2#execute", "Cmd2#post",
12
- "Cmd3#pre", "Cmd3#execute", "Cmd3#post"]
10
+ ["Cmd1#before", "Cmd1#execute", "Cmd1#after",
11
+ "Cmd2#before", "Cmd2#execute", "Cmd2#after",
12
+ "Cmd3#before", "Cmd3#execute", "Cmd3#after"]
13
13
  end
14
14
  end
15
15
 
16
16
  describe "#benchmark" do
17
- it "should call its and sub commands's {pre,execute,post} in declared order" do
17
+ it "should call its and sub commands's {before,execute,after} in declared order" do
18
18
  c = Program.new
19
19
  c.data[:breadcrumbs] = []
20
20
  c.benchmark
21
21
  c.data[:breadcrumbs].should ==
22
- ["Program#pre",
23
- "Cmd1#pre", "Cmd1#execute", "Cmd1#post",
24
- "Cmd2#pre", "Cmd2#execute", "Cmd2#post",
25
- "Cmd3#pre", "Cmd3#execute", "Cmd3#post",
26
- "Program#post"]
22
+ ["Program#before",
23
+ "Cmd1#before", "Cmd1#execute", "Cmd1#after",
24
+ "Cmd2#before", "Cmd2#execute", "Cmd2#after",
25
+ "Cmd3#before", "Cmd3#execute", "Cmd3#after",
26
+ "Program#after"]
27
27
  end
28
28
  end
29
29
  end
30
30
 
31
31
  describe "Ccp::Commands::Composite(nested)" do
32
32
  describe "#execute" do
33
- it "should call its execute and sub commands's {pre,execute,post} in declared order" do
33
+ it "should call its execute and sub commands's {before,execute,after} in declared order" do
34
34
  c = CompositeProgram.new
35
35
  c.data[:breadcrumbs] = []
36
36
  c.execute
37
37
  c.data[:breadcrumbs].should ==
38
- ["Cmd1#pre", "Cmd1#execute", "Cmd1#post",
39
- "Cmd23#pre",
38
+ ["Cmd1#before", "Cmd1#execute", "Cmd1#after",
39
+ "Cmd23#before",
40
40
  "Cmd23#execute:start",
41
- "Cmd2#pre", "Cmd2#execute", "Cmd2#post",
42
- "Cmd3#pre", "Cmd3#execute", "Cmd3#post",
41
+ "Cmd2#before", "Cmd2#execute", "Cmd2#after",
42
+ "Cmd3#before", "Cmd3#execute", "Cmd3#after",
43
43
  "Cmd23#execute:end",
44
- "Cmd23#post",
45
- "Cmd4#pre", "Cmd4#execute", "Cmd4#post"]
44
+ "Cmd23#after",
45
+ "Cmd4#before", "Cmd4#execute", "Cmd4#after"]
46
46
  end
47
47
  end
48
48
 
49
49
  describe "#benchmark" do
50
- it "should call its and sub commands's {pre,execute,post} in declared order" do
50
+ it "should call its and sub commands's {before,execute,after} in declared order" do
51
51
  c = CompositeProgram.new
52
52
  c.data[:breadcrumbs] = []
53
53
  c.benchmark
54
54
  c.data[:breadcrumbs].should ==
55
- ["CompositeProgram#pre",
56
- "Cmd1#pre", "Cmd1#execute", "Cmd1#post",
57
- "Cmd23#pre",
55
+ ["CompositeProgram#before",
56
+ "Cmd1#before", "Cmd1#execute", "Cmd1#after",
57
+ "Cmd23#before",
58
58
  "Cmd23#execute:start",
59
- "Cmd2#pre", "Cmd2#execute", "Cmd2#post",
60
- "Cmd3#pre", "Cmd3#execute", "Cmd3#post",
59
+ "Cmd2#before", "Cmd2#execute", "Cmd2#after",
60
+ "Cmd3#before", "Cmd3#execute", "Cmd3#after",
61
61
  "Cmd23#execute:end",
62
- "Cmd23#post",
63
- "Cmd4#pre", "Cmd4#execute", "Cmd4#post",
64
- "CompositeProgram#post"]
62
+ "Cmd23#after",
63
+ "Cmd4#before", "Cmd4#execute", "Cmd4#after",
64
+ "CompositeProgram#after"]
65
65
  end
66
66
  end
67
67
 
@@ -28,11 +28,11 @@ describe Ccp::Commands::Core do
28
28
  end
29
29
 
30
30
  describe "#benchmark" do
31
- it "should call {pre,execute,post}" do
31
+ it "should call {before,execute,after}" do
32
32
  cmd1 = Cmd1.new
33
33
  cmd1.data[:breadcrumbs] = []
34
34
  cmd1.benchmark
35
- cmd1.data[:breadcrumbs].should == ["Cmd1#pre", "Cmd1#execute", "Cmd1#post"]
35
+ cmd1.data[:breadcrumbs].should == ["Cmd1#before", "Cmd1#execute", "Cmd1#after"]
36
36
  end
37
37
 
38
38
  it "should call receiver.profile" do
@@ -4,55 +4,55 @@ describe Ccp::Invokers::Base do
4
4
  def no_logger; Logger.new('/dev/null'); end
5
5
 
6
6
  describe "#execute" do
7
- it "should call its execute and sub commands's {pre,execute,post} in declared order" do
7
+ it "should call its execute and sub commands's {before,execute,after} in declared order" do
8
8
  c = CompositeInvoker.new
9
9
  c.data[:breadcrumbs] = []
10
10
  c.execute
11
11
  c.data[:breadcrumbs].should ==
12
- ["Cmd1#pre", "Cmd1#execute", "Cmd1#post",
13
- "Cmd23#pre",
12
+ ["Cmd1#before", "Cmd1#execute", "Cmd1#after",
13
+ "Cmd23#before",
14
14
  "Cmd23#execute:start",
15
- "Cmd2#pre", "Cmd2#execute", "Cmd2#post",
16
- "Cmd3#pre", "Cmd3#execute", "Cmd3#post",
15
+ "Cmd2#before", "Cmd2#execute", "Cmd2#after",
16
+ "Cmd3#before", "Cmd3#execute", "Cmd3#after",
17
17
  "Cmd23#execute:end",
18
- "Cmd23#post",
19
- "Cmd4#pre", "Cmd4#execute", "Cmd4#post"]
18
+ "Cmd23#after",
19
+ "Cmd4#before", "Cmd4#execute", "Cmd4#after"]
20
20
  end
21
21
  end
22
22
 
23
23
  describe "#benchmark" do
24
- it "should call its and sub commands's {pre,execute,post} in declared order" do
24
+ it "should call its and sub commands's {before,execute,after} in declared order" do
25
25
  c = CompositeInvoker.new
26
26
  c.data[:breadcrumbs] = []
27
27
  c.benchmark
28
28
  c.data[:breadcrumbs].should ==
29
- ["CompositeInvoker#pre",
30
- "Cmd1#pre", "Cmd1#execute", "Cmd1#post",
31
- "Cmd23#pre",
29
+ ["CompositeInvoker#before",
30
+ "Cmd1#before", "Cmd1#execute", "Cmd1#after",
31
+ "Cmd23#before",
32
32
  "Cmd23#execute:start",
33
- "Cmd2#pre", "Cmd2#execute", "Cmd2#post",
34
- "Cmd3#pre", "Cmd3#execute", "Cmd3#post",
33
+ "Cmd2#before", "Cmd2#execute", "Cmd2#after",
34
+ "Cmd3#before", "Cmd3#execute", "Cmd3#after",
35
35
  "Cmd23#execute:end",
36
- "Cmd23#post",
37
- "Cmd4#pre", "Cmd4#execute", "Cmd4#post",
38
- "CompositeInvoker#post"]
36
+ "Cmd23#after",
37
+ "Cmd4#before", "Cmd4#execute", "Cmd4#after",
38
+ "CompositeInvoker#after"]
39
39
  end
40
40
  end
41
41
 
42
42
  describe ".execute" do
43
- it "should call its and sub commands's {pre,execute,post} in declared order" do
43
+ it "should call its and sub commands's {before,execute,after} in declared order" do
44
44
  c = CompositeInvoker.execute(:breadcrumbs => [])
45
45
  c.data[:breadcrumbs].should ==
46
- ["CompositeInvoker#pre",
47
- "Cmd1#pre", "Cmd1#execute", "Cmd1#post",
48
- "Cmd23#pre",
46
+ ["CompositeInvoker#before",
47
+ "Cmd1#before", "Cmd1#execute", "Cmd1#after",
48
+ "Cmd23#before",
49
49
  "Cmd23#execute:start",
50
- "Cmd2#pre", "Cmd2#execute", "Cmd2#post",
51
- "Cmd3#pre", "Cmd3#execute", "Cmd3#post",
50
+ "Cmd2#before", "Cmd2#execute", "Cmd2#after",
51
+ "Cmd3#before", "Cmd3#execute", "Cmd3#after",
52
52
  "Cmd23#execute:end",
53
- "Cmd23#post",
54
- "Cmd4#pre", "Cmd4#execute", "Cmd4#post",
55
- "CompositeInvoker#post"]
53
+ "Cmd23#after",
54
+ "Cmd4#before", "Cmd4#execute", "Cmd4#after",
55
+ "CompositeInvoker#after"]
56
56
  end
57
57
 
58
58
  it "should call only show_comments in default" do
@@ -76,23 +76,23 @@ describe Ccp::Invokers::Base do
76
76
  end
77
77
 
78
78
  describe ".benchmark" do
79
- it "should call its and sub commands's {pre,execute,post} in declared order" do
79
+ it "should call its and sub commands's {before,execute,after} in declared order" do
80
80
  r = Ccp::Receivers::Base.new
81
81
  r.stub!(:show_comments) # disable output
82
82
  r.stub!(:show_profiles) # disable output
83
83
 
84
84
  c = CompositeInvoker.benchmark(:receiver => r, :breadcrumbs => [])
85
85
  c.data[:breadcrumbs].should ==
86
- ["CompositeInvoker#pre",
87
- "Cmd1#pre", "Cmd1#execute", "Cmd1#post",
88
- "Cmd23#pre",
86
+ ["CompositeInvoker#before",
87
+ "Cmd1#before", "Cmd1#execute", "Cmd1#after",
88
+ "Cmd23#before",
89
89
  "Cmd23#execute:start",
90
- "Cmd2#pre", "Cmd2#execute", "Cmd2#post",
91
- "Cmd3#pre", "Cmd3#execute", "Cmd3#post",
90
+ "Cmd2#before", "Cmd2#execute", "Cmd2#after",
91
+ "Cmd3#before", "Cmd3#execute", "Cmd3#after",
92
92
  "Cmd23#execute:end",
93
- "Cmd23#post",
94
- "Cmd4#pre", "Cmd4#execute", "Cmd4#post",
95
- "CompositeInvoker#post"]
93
+ "Cmd23#after",
94
+ "Cmd4#before", "Cmd4#execute", "Cmd4#after",
95
+ "CompositeInvoker#after"]
96
96
  end
97
97
 
98
98
  it "should call only show_comments in default" do
data/spec/models.rb CHANGED
@@ -8,7 +8,7 @@ class Cmd1
8
8
  include Ccp::Commands::Core
9
9
  include Breadcrumbing
10
10
 
11
- def pre
11
+ def before
12
12
  data[:breadcrumbs] << this
13
13
  end
14
14
 
@@ -16,7 +16,7 @@ class Cmd1
16
16
  data[:breadcrumbs] << this
17
17
  end
18
18
 
19
- def post
19
+ def after
20
20
  data[:breadcrumbs] << this
21
21
  end
22
22
  end
@@ -33,11 +33,11 @@ class Program
33
33
  command Cmd2
34
34
  command Cmd3
35
35
 
36
- def pre
36
+ def before
37
37
  data[:breadcrumbs] << this
38
38
  end
39
39
 
40
- def post
40
+ def after
41
41
  data[:breadcrumbs] << this
42
42
  end
43
43
  end
@@ -49,7 +49,7 @@ class Cmd23
49
49
  command Cmd2
50
50
  command Cmd3
51
51
 
52
- def pre
52
+ def before
53
53
  data[:breadcrumbs] << this
54
54
  end
55
55
 
@@ -59,7 +59,7 @@ class Cmd23
59
59
  data[:breadcrumbs] << this + ":end"
60
60
  end
61
61
 
62
- def post
62
+ def after
63
63
  data[:breadcrumbs] << this
64
64
  end
65
65
  end
@@ -72,11 +72,11 @@ class CompositeProgram
72
72
  command Cmd23
73
73
  command Cmd4
74
74
 
75
- def pre
75
+ def before
76
76
  data[:breadcrumbs] << this
77
77
  end
78
78
 
79
- def post
79
+ def after
80
80
  data[:breadcrumbs] << this
81
81
  end
82
82
  end
@@ -88,11 +88,12 @@ class CompositeInvoker < Ccp::Invokers::Base
88
88
  command Cmd23
89
89
  command Cmd4
90
90
 
91
- def pre
91
+ def before
92
92
  data[:breadcrumbs] << this
93
93
  end
94
94
 
95
- def post
95
+ def after
96
96
  data[:breadcrumbs] << this
97
+ super
97
98
  end
98
99
  end
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: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - maiha