zertico 0.6.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -1
- data/lib/zertico.rb +1 -0
- data/lib/zertico/accessor.rb +3 -3
- data/lib/zertico/controller.rb +14 -35
- data/lib/zertico/responder.rb +32 -0
- data/lib/zertico/service.rb +22 -14
- data/lib/zertico/version.rb +1 -1
- data/spec/fake_app/user.rb +1 -1
- data/spec/zertico/accessor_spec.rb +1 -1
- data/spec/zertico/controller_spec.rb +106 -89
- data/spec/zertico/service_spec.rb +77 -25
- data/zertico.gemspec +4 -3
- metadata +8 -6
data/.rspec
CHANGED
@@ -1 +1 @@
|
|
1
|
-
--colour --format documentation --profile
|
1
|
+
--colour --format documentation --profile
|
data/lib/zertico.rb
CHANGED
data/lib/zertico/accessor.rb
CHANGED
@@ -13,14 +13,14 @@ module Zertico
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def method_missing(method_name, *args)
|
16
|
-
if
|
17
|
-
return
|
16
|
+
if interface.respond_to?(method_name)
|
17
|
+
return interface.send(method_name, *args)
|
18
18
|
end
|
19
19
|
super
|
20
20
|
end
|
21
21
|
|
22
22
|
def respond_to_missing?(method_name, include_private = false)
|
23
|
-
return true if
|
23
|
+
return true if interface.respond_to?(method_name)
|
24
24
|
super
|
25
25
|
end
|
26
26
|
|
data/lib/zertico/controller.rb
CHANGED
@@ -12,59 +12,38 @@ module Zertico
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def index
|
15
|
-
|
16
|
-
respond_with(
|
15
|
+
all
|
16
|
+
respond_with(@responder, @options)
|
17
17
|
end
|
18
18
|
|
19
19
|
def new
|
20
|
-
|
21
|
-
respond_with(
|
20
|
+
build
|
21
|
+
respond_with(@responder, @options)
|
22
22
|
end
|
23
23
|
|
24
24
|
def show
|
25
|
-
|
26
|
-
respond_with(
|
25
|
+
find
|
26
|
+
respond_with(@responder, @options)
|
27
27
|
end
|
28
28
|
|
29
29
|
def edit
|
30
|
-
|
31
|
-
respond_with(
|
30
|
+
find
|
31
|
+
respond_with(@responder, @options)
|
32
32
|
end
|
33
33
|
|
34
34
|
def create
|
35
|
-
|
36
|
-
|
37
|
-
respond_with(instance_variable_get('@responder'), :location => instance_variable_get('@location'))
|
38
|
-
else
|
39
|
-
respond_with(instance_variable_get('@responder'))
|
40
|
-
end
|
35
|
+
generate
|
36
|
+
respond_with(@responder, @options)
|
41
37
|
end
|
42
38
|
|
43
39
|
def update
|
44
|
-
|
45
|
-
|
46
|
-
respond_with(instance_variable_get('@responder'), :location => instance_variable_get('@location'))
|
47
|
-
else
|
48
|
-
respond_with(instance_variable_get('@responder'))
|
49
|
-
end
|
40
|
+
modify
|
41
|
+
respond_with(@responder, @options)
|
50
42
|
end
|
51
43
|
|
52
44
|
def destroy
|
53
|
-
|
54
|
-
|
55
|
-
respond_with(instance_variable_get('@responder'), :location => instance_variable_get('@location'))
|
56
|
-
else
|
57
|
-
respond_with(instance_variable_get('@responder'))
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
protected
|
62
|
-
|
63
|
-
def initialize_object(objects = {})
|
64
|
-
objects.each do |key, value|
|
65
|
-
instance_variable_set("@#{key}", value)
|
66
|
-
instance_variable_set('@responder', value) unless @responder
|
67
|
-
end
|
45
|
+
delete
|
46
|
+
respond_with(@responder, @options)
|
68
47
|
end
|
69
48
|
end
|
70
49
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Zertico
|
2
|
+
module Responder
|
3
|
+
def initialize(controller, resources, options={})
|
4
|
+
super
|
5
|
+
@force_redirect = options.delete(:force_redirect)
|
6
|
+
end
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def navigation_behavior(error)
|
11
|
+
if get?
|
12
|
+
raise error
|
13
|
+
elsif has_errors? && default_action
|
14
|
+
if @force_redirect
|
15
|
+
controller.flash.keep
|
16
|
+
redirect_to navigation_location
|
17
|
+
else
|
18
|
+
controller.flash.clear
|
19
|
+
render :action => default_action
|
20
|
+
end
|
21
|
+
else
|
22
|
+
controller.flash.keep
|
23
|
+
redirect_to navigation_location
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def set_flash_message?
|
28
|
+
return @force_redirect unless @force_redirect.nil?
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/zertico/service.rb
CHANGED
@@ -1,31 +1,39 @@
|
|
1
1
|
module Zertico
|
2
2
|
module Service
|
3
3
|
def all
|
4
|
-
|
4
|
+
@responder = resource.all
|
5
|
+
instance_variable_set("@#{interface_name.pluralize}", @responder)
|
6
|
+
@options = {}
|
5
7
|
end
|
6
8
|
|
7
9
|
def build
|
8
|
-
|
10
|
+
@responder = resource.new
|
11
|
+
instance_variable_set("@#{interface_name}", @responder)
|
12
|
+
@options = {}
|
9
13
|
end
|
10
14
|
|
11
|
-
def find
|
12
|
-
|
15
|
+
def find
|
16
|
+
@responder = resource.find(params[interface_id.to_sym])
|
17
|
+
instance_variable_set("@#{interface_name}", @responder)
|
18
|
+
@options = {}
|
13
19
|
end
|
14
20
|
|
15
|
-
def generate
|
16
|
-
|
21
|
+
def generate
|
22
|
+
@responder = resource.create(params[interface_name.to_sym])
|
23
|
+
instance_variable_set("@#{interface_name}", @responder)
|
24
|
+
@options = {}
|
17
25
|
end
|
18
26
|
|
19
|
-
def modify
|
20
|
-
|
21
|
-
|
22
|
-
|
27
|
+
def modify
|
28
|
+
find
|
29
|
+
@responder.update_attributes(params[interface_name.to_sym])
|
30
|
+
@options = {}
|
23
31
|
end
|
24
32
|
|
25
|
-
def delete
|
26
|
-
|
27
|
-
|
28
|
-
|
33
|
+
def delete
|
34
|
+
find
|
35
|
+
@responder.destroy
|
36
|
+
@options = {}
|
29
37
|
end
|
30
38
|
|
31
39
|
def resource
|
data/lib/zertico/version.rb
CHANGED
data/spec/fake_app/user.rb
CHANGED
@@ -57,7 +57,7 @@ describe Zertico::Accessor do
|
|
57
57
|
|
58
58
|
describe '#method_missing' do
|
59
59
|
it 'should pass the method to the interface model if it responds to it' do
|
60
|
-
|
60
|
+
user_accessor.should respond_to(:full_name)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -33,120 +33,137 @@ describe Zertico::Controller do
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
context '
|
36
|
+
context 'actions' do
|
37
37
|
before :each do
|
38
|
-
controller.
|
39
|
-
controller.
|
40
|
-
controller.
|
38
|
+
controller.instance_variable_set('@responder', 'responder')
|
39
|
+
controller.instance_variable_set('@options', 'options')
|
40
|
+
controller.stub(:respond_with).with('responder', 'options')
|
41
41
|
end
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
context '#index' do
|
44
|
+
before :each do
|
45
|
+
controller.stub(:all)
|
46
|
+
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
controller.stub(:params).and_return({ :user => 'user' })
|
52
|
-
controller.stub(:generate => { :user => 'user', :location => 'admin_location' } )
|
53
|
-
controller.stub(:respond_with)
|
54
|
-
controller.create
|
55
|
-
end
|
48
|
+
after :each do
|
49
|
+
controller.index
|
50
|
+
end
|
56
51
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
52
|
+
it 'should initialize a collection of objects' do
|
53
|
+
controller.should_receive(:all)
|
54
|
+
end
|
61
55
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
controller.stub(:respond_with)
|
66
|
-
controller.index
|
56
|
+
it 'should respond correctly' do
|
57
|
+
controller.should_receive(:respond_with).with('responder', 'options')
|
58
|
+
end
|
67
59
|
end
|
68
60
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
61
|
+
context '#new' do
|
62
|
+
before :each do
|
63
|
+
controller.stub(:build)
|
64
|
+
end
|
73
65
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
controller.stub(:respond_with)
|
78
|
-
controller.new
|
79
|
-
end
|
66
|
+
after :each do
|
67
|
+
controller.new
|
68
|
+
end
|
80
69
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end
|
70
|
+
it 'should initialize an object' do
|
71
|
+
controller.should_receive(:build)
|
72
|
+
end
|
85
73
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
controller.stub(:find).and_return({ :user => 'user' })
|
90
|
-
controller.stub(:respond_with)
|
91
|
-
controller.show
|
74
|
+
it 'should respond correctly' do
|
75
|
+
controller.should_receive(:respond_with).with('responder', 'options')
|
76
|
+
end
|
92
77
|
end
|
93
78
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
79
|
+
context '#show' do
|
80
|
+
before :each do
|
81
|
+
controller.stub(:find)
|
82
|
+
end
|
98
83
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
controller.stub(:find).and_return({ :user => 'user' })
|
103
|
-
controller.stub(:respond_with)
|
104
|
-
controller.edit
|
105
|
-
end
|
84
|
+
after :each do
|
85
|
+
controller.show
|
86
|
+
end
|
106
87
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
end
|
88
|
+
it 'should initialize an object' do
|
89
|
+
controller.should_receive(:find)
|
90
|
+
end
|
111
91
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
controller.stub(:params).and_return({ :user => 'user' })
|
116
|
-
controller.stub(:generate => { :user => 'user' } )
|
117
|
-
controller.stub(:respond_with)
|
118
|
-
controller.create
|
92
|
+
it 'should respond correctly' do
|
93
|
+
controller.should_receive(:respond_with).with('responder', 'options')
|
94
|
+
end
|
119
95
|
end
|
120
96
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
97
|
+
context '#edit' do
|
98
|
+
before :each do
|
99
|
+
controller.stub(:find)
|
100
|
+
end
|
125
101
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
102
|
+
after :each do
|
103
|
+
controller.edit
|
104
|
+
end
|
105
|
+
|
106
|
+
it 'should initialize an object' do
|
107
|
+
controller.should_receive(:find)
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should respond correctly' do
|
111
|
+
controller.should_receive(:respond_with).with('responder', 'options')
|
112
|
+
end
|
133
113
|
end
|
134
114
|
|
135
|
-
|
136
|
-
|
115
|
+
context '#create' do
|
116
|
+
before :each do
|
117
|
+
controller.stub(:generate)
|
118
|
+
end
|
119
|
+
|
120
|
+
after :each do
|
121
|
+
controller.create
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should initialize an object' do
|
125
|
+
controller.should_receive(:generate)
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should respond correctly' do
|
129
|
+
controller.should_receive(:respond_with).with('responder', 'options')
|
130
|
+
end
|
137
131
|
end
|
138
|
-
end
|
139
132
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
133
|
+
context '#update' do
|
134
|
+
before :each do
|
135
|
+
controller.stub(:modify)
|
136
|
+
end
|
137
|
+
|
138
|
+
after :each do
|
139
|
+
controller.update
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should initialize an object' do
|
143
|
+
controller.should_receive(:modify)
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'should respond correctly' do
|
147
|
+
controller.should_receive(:respond_with).with('responder', 'options')
|
148
|
+
end
|
146
149
|
end
|
147
150
|
|
148
|
-
|
149
|
-
|
151
|
+
context '#destroy' do
|
152
|
+
before :each do
|
153
|
+
controller.stub(:delete)
|
154
|
+
end
|
155
|
+
|
156
|
+
after :each do
|
157
|
+
controller.destroy
|
158
|
+
end
|
159
|
+
|
160
|
+
it 'should initialize an object' do
|
161
|
+
controller.should_receive(:delete)
|
162
|
+
end
|
163
|
+
|
164
|
+
it 'should respond correctly' do
|
165
|
+
controller.should_receive(:respond_with).with('responder', 'options')
|
166
|
+
end
|
150
167
|
end
|
151
168
|
end
|
152
169
|
end
|
@@ -33,69 +33,121 @@ describe Zertico::Service do
|
|
33
33
|
|
34
34
|
context '#all' do
|
35
35
|
before :each do
|
36
|
-
|
37
|
-
controller.
|
36
|
+
User.stub(:all => [])
|
37
|
+
controller.all
|
38
38
|
end
|
39
39
|
|
40
|
-
it 'should
|
41
|
-
controller.
|
40
|
+
it 'should save a collection on an instance variable' do
|
41
|
+
controller.instance_variable_get('@users').should == []
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should save the object on an instance variable to respond' do
|
45
|
+
controller.instance_variable_get('@responder').should == []
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should save a hash with options on an instance variable' do
|
49
|
+
controller.instance_variable_get('@options').should == {}
|
42
50
|
end
|
43
51
|
end
|
44
52
|
|
45
53
|
context '#build' do
|
46
54
|
before :each do
|
47
|
-
|
48
|
-
controller.
|
55
|
+
User.stub(:new => object)
|
56
|
+
controller.build
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should save an object on an instance variable' do
|
60
|
+
controller.instance_variable_get('@user').should == object
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should save the object on an instance variable to respond' do
|
64
|
+
controller.instance_variable_get('@responder').should == object
|
49
65
|
end
|
50
66
|
|
51
|
-
it 'should
|
52
|
-
controller.
|
67
|
+
it 'should save a hash with options on an instance variable' do
|
68
|
+
controller.instance_variable_get('@options').should == {}
|
53
69
|
end
|
54
70
|
end
|
55
71
|
|
56
72
|
context '#find' do
|
57
73
|
before :each do
|
58
|
-
|
59
|
-
controller.
|
74
|
+
User.stub(:find => object)
|
75
|
+
controller.stub(:params => { :id => 1 })
|
76
|
+
controller.find
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should save an object on an instance variable' do
|
80
|
+
controller.instance_variable_get('@user').should == object
|
60
81
|
end
|
61
82
|
|
62
|
-
it 'should
|
63
|
-
controller.
|
83
|
+
it 'should save the object on an instance variable to respond' do
|
84
|
+
controller.instance_variable_get('@responder').should == object
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should save a hash with options on an instance variable' do
|
88
|
+
controller.instance_variable_get('@options').should == {}
|
64
89
|
end
|
65
90
|
end
|
66
91
|
|
67
92
|
context '#generate' do
|
68
93
|
before :each do
|
69
|
-
|
70
|
-
controller.
|
94
|
+
User.stub(:create => object)
|
95
|
+
controller.stub(:params => { :user => {} })
|
96
|
+
controller.generate
|
71
97
|
end
|
72
98
|
|
73
|
-
it 'should
|
74
|
-
controller.
|
99
|
+
it 'should save an object on an instance variable' do
|
100
|
+
controller.instance_variable_get('@user').should == object
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should save the object on an instance variable to respond' do
|
104
|
+
controller.instance_variable_get('@responder').should == object
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should save a hash with options on an instance variable' do
|
108
|
+
controller.instance_variable_get('@options').should == {}
|
75
109
|
end
|
76
110
|
end
|
77
111
|
|
78
112
|
context '#modify' do
|
79
113
|
before :each do
|
80
|
-
|
114
|
+
User.stub(:find => object)
|
115
|
+
controller.stub(:params => { :id => 1, :user => {} })
|
81
116
|
object.stub(:update_attributes).with({}).and_return(true)
|
82
|
-
controller.
|
117
|
+
controller.modify
|
83
118
|
end
|
84
119
|
|
85
|
-
it 'should
|
86
|
-
controller.
|
120
|
+
it 'should save an object on an instance variable' do
|
121
|
+
controller.instance_variable_get('@user').should == object
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should save the object on an instance variable to respond' do
|
125
|
+
controller.instance_variable_get('@responder').should == object
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should save a hash with options on an instance variable' do
|
129
|
+
controller.instance_variable_get('@options').should == {}
|
87
130
|
end
|
88
131
|
end
|
89
132
|
|
90
133
|
context '#delete' do
|
91
134
|
before :each do
|
92
|
-
|
93
|
-
|
94
|
-
|
135
|
+
User.stub(:find => object)
|
136
|
+
controller.stub(:params => { :id => 1 })
|
137
|
+
object.stub(:destroy => true)
|
138
|
+
controller.delete
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'should save an object on an instance variable' do
|
142
|
+
controller.instance_variable_get('@user').should == object
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should save the object on an instance variable to respond' do
|
146
|
+
controller.instance_variable_get('@responder').should == object
|
95
147
|
end
|
96
148
|
|
97
|
-
it 'should
|
98
|
-
controller.
|
149
|
+
it 'should save a hash with options on an instance variable' do
|
150
|
+
controller.instance_variable_get('@options').should == {}
|
99
151
|
end
|
100
152
|
end
|
101
153
|
|
data/zertico.gemspec
CHANGED
@@ -7,14 +7,15 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.name = "zertico"
|
8
8
|
gem.version = Zertico::VERSION
|
9
9
|
gem.authors = ['Paulo Henrique Lopes Ribeiro']
|
10
|
-
gem.email =
|
10
|
+
gem.email = %w(plribeiro3000@gmail.com)
|
11
11
|
gem.description = %q{Easy Rails development using the Zertico Way}
|
12
|
-
gem.summary = %q{Models and patterns used by Zertico}
|
12
|
+
gem.summary = %q{Models and patterns used by Zertico to achieve greater agility}
|
13
|
+
gem.license = 'MIT'
|
13
14
|
|
14
15
|
gem.files = `git ls-files`.split($/)
|
15
16
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
16
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features|gemfiles)/})
|
17
|
-
gem.require_paths =
|
18
|
+
gem.require_paths = %w(lib)
|
18
19
|
|
19
20
|
gem.add_runtime_dependency 'rails', '>= 3.0.0'
|
20
21
|
gem.add_development_dependency 'rspec'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zertico
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-09-
|
12
|
+
date: 2013-09-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/zertico.rb
|
81
81
|
- lib/zertico/accessor.rb
|
82
82
|
- lib/zertico/controller.rb
|
83
|
+
- lib/zertico/responder.rb
|
83
84
|
- lib/zertico/service.rb
|
84
85
|
- lib/zertico/version.rb
|
85
86
|
- spec/fake_app/admin/user_accessor.rb
|
@@ -100,7 +101,8 @@ files:
|
|
100
101
|
- spec/zertico/service_spec.rb
|
101
102
|
- zertico.gemspec
|
102
103
|
homepage:
|
103
|
-
licenses:
|
104
|
+
licenses:
|
105
|
+
- MIT
|
104
106
|
post_install_message:
|
105
107
|
rdoc_options: []
|
106
108
|
require_paths:
|
@@ -113,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
113
115
|
version: '0'
|
114
116
|
segments:
|
115
117
|
- 0
|
116
|
-
hash:
|
118
|
+
hash: 601803739773606042
|
117
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
120
|
none: false
|
119
121
|
requirements:
|
@@ -122,13 +124,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
124
|
version: '0'
|
123
125
|
segments:
|
124
126
|
- 0
|
125
|
-
hash:
|
127
|
+
hash: 601803739773606042
|
126
128
|
requirements: []
|
127
129
|
rubyforge_project:
|
128
130
|
rubygems_version: 1.8.25
|
129
131
|
signing_key:
|
130
132
|
specification_version: 3
|
131
|
-
summary: Models and patterns used by Zertico
|
133
|
+
summary: Models and patterns used by Zertico to achieve greater agility
|
132
134
|
test_files:
|
133
135
|
- gemfiles/Gemfile.rails3.1
|
134
136
|
- gemfiles/Gemfile.rails3.2
|