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 CHANGED
@@ -1 +1 @@
1
- --colour --format documentation --profile
1
+ --colour --format documentation --profile
@@ -5,4 +5,5 @@ module Zertico
5
5
  autoload :Controller, 'zertico/controller'
6
6
  autoload :Service, 'zertico/service'
7
7
  autoload :Accessor, 'zertico/accessor'
8
+ autoload :Responder, 'zertico/responder'
8
9
  end
@@ -13,14 +13,14 @@ module Zertico
13
13
  end
14
14
 
15
15
  def method_missing(method_name, *args)
16
- if instance_variable_get("@#{interface_name}").respond_to?(method_name)
17
- return instance_variable_get("@#{interface_name}").send(method_name, *args)
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 interface_class.respond_to?(method_name)
23
+ return true if interface.respond_to?(method_name)
24
24
  super
25
25
  end
26
26
 
@@ -12,59 +12,38 @@ module Zertico
12
12
  end
13
13
 
14
14
  def index
15
- initialize_object all
16
- respond_with(instance_variable_get('@responder'))
15
+ all
16
+ respond_with(@responder, @options)
17
17
  end
18
18
 
19
19
  def new
20
- initialize_object build
21
- respond_with(instance_variable_get('@responder'))
20
+ build
21
+ respond_with(@responder, @options)
22
22
  end
23
23
 
24
24
  def show
25
- initialize_object find(params[interface_id.to_sym])
26
- respond_with(instance_variable_get('@responder'))
25
+ find
26
+ respond_with(@responder, @options)
27
27
  end
28
28
 
29
29
  def edit
30
- initialize_object find(params[interface_id.to_sym])
31
- respond_with(instance_variable_get('@responder'))
30
+ find
31
+ respond_with(@responder, @options)
32
32
  end
33
33
 
34
34
  def create
35
- initialize_object generate(params[interface_name.to_sym])
36
- if instance_variable_defined?('@location')
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
- initialize_object modify(params[interface_id.to_sym], params[interface_name.to_sym])
45
- if instance_variable_defined?('@location')
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
- initialize_object delete(params[interface_id.to_sym])
54
- if instance_variable_defined?('@location')
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
@@ -1,31 +1,39 @@
1
1
  module Zertico
2
2
  module Service
3
3
  def all
4
- { interface_name.pluralize.to_sym => resource.all }
4
+ @responder = resource.all
5
+ instance_variable_set("@#{interface_name.pluralize}", @responder)
6
+ @options = {}
5
7
  end
6
8
 
7
9
  def build
8
- { interface_name.to_sym => resource.new }
10
+ @responder = resource.new
11
+ instance_variable_set("@#{interface_name}", @responder)
12
+ @options = {}
9
13
  end
10
14
 
11
- def find(id)
12
- { interface_name.to_sym => resource.find(id) }
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(attributes = {})
16
- { interface_name.to_sym => resource.create(attributes) }
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(id, attributes = {})
20
- object = self.find(id)[interface_name.to_sym]
21
- object.update_attributes(attributes)
22
- { interface_name.to_sym => object }
27
+ def modify
28
+ find
29
+ @responder.update_attributes(params[interface_name.to_sym])
30
+ @options = {}
23
31
  end
24
32
 
25
- def delete(id)
26
- object = self.find(id)[interface_name.to_sym]
27
- object.destroy
28
- { interface_name.to_sym => object }
33
+ def delete
34
+ find
35
+ @responder.destroy
36
+ @options = {}
29
37
  end
30
38
 
31
39
  def resource
@@ -1,3 +1,3 @@
1
1
  module Zertico
2
- VERSION = '0.6.1'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -1,5 +1,5 @@
1
1
  class User
2
- def name
2
+ def full_name
3
3
  'User Name'
4
4
  end
5
5
  end
@@ -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
- UserAccessor.new(user).should respond_to(:name)
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 'with a custom object to respond' do
36
+ context 'actions' do
37
37
  before :each do
38
- controller.stub(:all).and_return({ :user => 'user', :responder => 'admin' })
39
- controller.stub(:respond_with)
40
- controller.index
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
- it 'should intialize an object with it' do
44
- controller.instance_variable_get('@responder').should == 'admin'
45
- end
46
- end
43
+ context '#index' do
44
+ before :each do
45
+ controller.stub(:all)
46
+ end
47
47
 
48
- context 'with a custom location to redirect' do
49
- before :each do
50
- controller.stub_chain(:interface_name, :to_sym).and_return(:user)
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
- it 'should intialize an object with it' do
58
- controller.instance_variable_get('@location').should == 'admin_location'
59
- end
60
- end
52
+ it 'should initialize a collection of objects' do
53
+ controller.should_receive(:all)
54
+ end
61
55
 
62
- context '#index' do
63
- before :each do
64
- controller.stub(:all).and_return({ :user => 'user' })
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
- it 'should initialize a collection of objects' do
70
- controller.instance_variable_get('@user').should == 'user'
71
- end
72
- end
61
+ context '#new' do
62
+ before :each do
63
+ controller.stub(:build)
64
+ end
73
65
 
74
- context '#new' do
75
- before :each do
76
- controller.stub(:build).and_return({ :user => 'user' })
77
- controller.stub(:respond_with)
78
- controller.new
79
- end
66
+ after :each do
67
+ controller.new
68
+ end
80
69
 
81
- it 'should initialize an object' do
82
- controller.instance_variable_get('@user').should == 'user'
83
- end
84
- end
70
+ it 'should initialize an object' do
71
+ controller.should_receive(:build)
72
+ end
85
73
 
86
- context '#show' do
87
- before :each do
88
- controller.stub(:params).and_return({ :id => 1 })
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
- it 'should initialize an object' do
95
- controller.instance_variable_get('@user').should == 'user'
96
- end
97
- end
79
+ context '#show' do
80
+ before :each do
81
+ controller.stub(:find)
82
+ end
98
83
 
99
- context '#edit' do
100
- before :each do
101
- controller.stub(:params).and_return({ :id => 1 })
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
- it 'should initialize an object' do
108
- controller.instance_variable_get('@user').should == 'user'
109
- end
110
- end
88
+ it 'should initialize an object' do
89
+ controller.should_receive(:find)
90
+ end
111
91
 
112
- context '#create' do
113
- before :each do
114
- controller.stub_chain(:interface_name, :to_sym).and_return(:user)
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
- it 'should create an object' do
122
- controller.instance_variable_get('@user').should == 'user'
123
- end
124
- end
97
+ context '#edit' do
98
+ before :each do
99
+ controller.stub(:find)
100
+ end
125
101
 
126
- context '#update' do
127
- before :each do
128
- controller.stub_chain(:interface_name, :to_sym).and_return(:user)
129
- controller.stub(:params).and_return({ :id => 1, :user => 'user' })
130
- controller.stub(:modify => { :user => 'user' })
131
- controller.stub(:respond_with)
132
- controller.update
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
- it 'should update an object' do
136
- controller.instance_variable_get('@user').should == 'user'
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
- context '#destroy' do
141
- before :each do
142
- controller.stub(:params).and_return({:id => 1})
143
- controller.stub(:delete => { :user => 'user' })
144
- controller.stub(:respond_with)
145
- controller.destroy
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
- it 'should destroy an object' do
149
- controller.instance_variable_get('@user').should == 'user'
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
- controller.stub_chain(:interface_name, :pluralize, :to_sym).and_return(:users)
37
- controller.stub_chain(:interface_class, :all).and_return([])
36
+ User.stub(:all => [])
37
+ controller.all
38
38
  end
39
39
 
40
- it 'should return a collection of objects' do
41
- controller.all.should == { :users => [] }
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
- controller.stub_chain(:interface_name, :to_sym).and_return(:person)
48
- controller.stub_chain(:interface_class, :new).and_return(object)
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 return a new object' do
52
- controller.build.should == { :person => object }
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
- controller.stub_chain(:interface_name, :to_sym).and_return(:person)
59
- controller.stub_chain(:interface_class, :find).with(1).and_return(object)
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 return the specified object' do
63
- controller.find(1).should == { :person => object }
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
- controller.stub_chain(:interface_name, :to_sym).and_return(:person)
70
- controller.stub_chain(:interface_class, :create).with({}).and_return(object)
94
+ User.stub(:create => object)
95
+ controller.stub(:params => { :user => {} })
96
+ controller.generate
71
97
  end
72
98
 
73
- it 'should return the created object' do
74
- controller.generate({}).should == { :person => object }
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
- controller.stub(:find).with(1).and_return({ :person => object })
114
+ User.stub(:find => object)
115
+ controller.stub(:params => { :id => 1, :user => {} })
81
116
  object.stub(:update_attributes).with({}).and_return(true)
82
- controller.stub_chain(:interface_name, :to_sym).and_return(:person)
117
+ controller.modify
83
118
  end
84
119
 
85
- it 'should return the updated object' do
86
- controller.modify(1, {}).should == { :person => object }
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
- controller.stub(:find).with(1).and_return({ :person => object })
93
- object.stub(:destroy).and_return(true)
94
- controller.stub_chain(:interface_name, :to_sym).and_return(:person)
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 return the destroyed object' do
98
- controller.delete(1).should == { :person => object }
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
 
@@ -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 = ['plribeiro3000@gmail.com']
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 = ['lib']
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.6.1
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-02 00:00:00.000000000 Z
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: 3377979383132618450
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: 3377979383132618450
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