zertico 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Rakefile +3 -3
- data/lib/zertico/accessor.rb +42 -0
- data/lib/zertico/controller.rb +2 -2
- data/lib/zertico/service.rb +1 -1
- data/lib/zertico/version.rb +2 -2
- data/lib/zertico.rb +5 -4
- data/spec/fake_app/user.rb +3 -0
- data/spec/fake_app/user_accessor.rb +2 -0
- data/spec/spec_helper.rb +2 -2
- data/spec/zertico/accessor_spec.rb +27 -0
- data/spec/zertico/controller_spec.rb +36 -36
- data/spec/zertico/service_spec.rb +16 -16
- data/zertico.gemspec +8 -9
- metadata +12 -5
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Zertico
|
2
|
+
class Accessor
|
3
|
+
def initialize(object)
|
4
|
+
instance_variable_set("@#{interface_name}", object)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.find(id)
|
8
|
+
instance_variable_set("@#{interface_name}", interface_class.find(id))
|
9
|
+
self
|
10
|
+
end
|
11
|
+
|
12
|
+
def method_missing(method_name, *args)
|
13
|
+
if instance_variable_get("@#{interface_name}").respond_to?(method_name)
|
14
|
+
return instance_variable_get("@#{interface_name}").send(method_name, *args)
|
15
|
+
end
|
16
|
+
super
|
17
|
+
end
|
18
|
+
|
19
|
+
def respond_to_missing?(method_name, include_private = false)
|
20
|
+
return true if interface_class.respond_to?(method_name)
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def self.interface_name
|
27
|
+
self.name.chomp('Accessor').singularize.underscore
|
28
|
+
end
|
29
|
+
|
30
|
+
def interface_name
|
31
|
+
self.class.name.chomp('Accessor').singularize.underscore
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.interface_class
|
35
|
+
self.interface_name.camelize.constantize
|
36
|
+
end
|
37
|
+
|
38
|
+
def interface_class
|
39
|
+
self.interface_name.camelize.constantize
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/zertico/controller.rb
CHANGED
data/lib/zertico/service.rb
CHANGED
data/lib/zertico/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Zertico
|
2
|
-
VERSION =
|
3
|
-
end
|
2
|
+
VERSION = '0.3.0'
|
3
|
+
end
|
data/lib/zertico.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'zertico/version'
|
2
|
+
require 'active_support/core_ext/string'
|
3
3
|
|
4
4
|
module Zertico
|
5
|
-
autoload :Controller,
|
6
|
-
autoload :Service,
|
5
|
+
autoload :Controller, 'zertico/controller'
|
6
|
+
autoload :Service, 'zertico/service'
|
7
|
+
autoload :Accessor, 'zertico/accessor'
|
7
8
|
end
|
data/spec/fake_app/user.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Zertico::Accessor do
|
4
|
+
let(:user) { User.new }
|
5
|
+
|
6
|
+
describe '.initialize' do
|
7
|
+
it 'should initialize the interface object on a instance variable' do
|
8
|
+
UserAccessor.new(user).instance_variable_get('@user').should == user
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.find' do
|
13
|
+
before :each do
|
14
|
+
User.stub(:find => user)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should initialize the interface object on a instance variable' do
|
18
|
+
UserAccessor.find(3).instance_variable_get('@user').should == user
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#method_missing' do
|
23
|
+
it 'should pass the method to the interface model if it responds to it' do
|
24
|
+
UserAccessor.new(user).should respond_to(:name)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,109 +1,109 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Zertico::Controller do
|
4
4
|
let(:controller) { Zertico::Controller.new }
|
5
5
|
let(:user_controller) { UserController.new }
|
6
6
|
|
7
|
-
context
|
8
|
-
it
|
7
|
+
context 'without a custom service' do
|
8
|
+
it 'should extend Zertico::Service' do
|
9
9
|
controller.should respond_to :all
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
context
|
14
|
-
it
|
13
|
+
context 'with a custom service' do
|
14
|
+
it 'should extend Zertico::Service' do
|
15
15
|
user_controller.should respond_to :all
|
16
16
|
end
|
17
17
|
|
18
|
-
it
|
18
|
+
it 'should extend it!' do
|
19
19
|
user_controller.should respond_to :user
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
context
|
23
|
+
context '#index' do
|
24
24
|
before :each do
|
25
|
-
controller.stub(:all).and_return({ :user =>
|
25
|
+
controller.stub(:all).and_return({ :user => 'user' })
|
26
26
|
controller.index
|
27
27
|
end
|
28
28
|
|
29
|
-
it
|
30
|
-
controller.instance_variable_get(
|
29
|
+
it 'should initialize a collection of objects' do
|
30
|
+
controller.instance_variable_get('@user').should == 'user'
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
context
|
34
|
+
context '#new' do
|
35
35
|
before :each do
|
36
|
-
controller.stub(:build).and_return({ :user =>
|
36
|
+
controller.stub(:build).and_return({ :user => 'user' })
|
37
37
|
controller.new
|
38
38
|
end
|
39
39
|
|
40
|
-
it
|
41
|
-
controller.instance_variable_get(
|
40
|
+
it 'should initialize an object' do
|
41
|
+
controller.instance_variable_get('@user').should == 'user'
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
context
|
45
|
+
context '#show' do
|
46
46
|
before :each do
|
47
47
|
controller.stub(:params).and_return({ :id => 1 })
|
48
|
-
controller.stub(:find).and_return({ :user =>
|
48
|
+
controller.stub(:find).and_return({ :user => 'user' })
|
49
49
|
controller.show
|
50
50
|
end
|
51
51
|
|
52
|
-
it
|
53
|
-
controller.instance_variable_get(
|
52
|
+
it 'should initialize an object' do
|
53
|
+
controller.instance_variable_get('@user').should == 'user'
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
-
context
|
57
|
+
context '#edit' do
|
58
58
|
before :each do
|
59
59
|
controller.stub(:params).and_return({ :id => 1 })
|
60
|
-
controller.stub(:find).and_return({ :user =>
|
60
|
+
controller.stub(:find).and_return({ :user => 'user' })
|
61
61
|
controller.edit
|
62
62
|
end
|
63
63
|
|
64
|
-
it
|
65
|
-
controller.instance_variable_get(
|
64
|
+
it 'should initialize an object' do
|
65
|
+
controller.instance_variable_get('@user').should == 'user'
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
|
-
context
|
69
|
+
context '#create' do
|
70
70
|
before :each do
|
71
71
|
controller.stub_chain(:interface_name, :to_sym).and_return(:user)
|
72
|
-
controller.stub(:params).and_return({ :user =>
|
73
|
-
controller.stub(:generate => { :user =>
|
72
|
+
controller.stub(:params).and_return({ :user => 'user' })
|
73
|
+
controller.stub(:generate => { :user => 'user' } )
|
74
74
|
controller.stub(:respond_with)
|
75
75
|
controller.create
|
76
76
|
end
|
77
77
|
|
78
|
-
it
|
79
|
-
controller.instance_variable_get(
|
78
|
+
it 'should create an object' do
|
79
|
+
controller.instance_variable_get('@user').should == 'user'
|
80
80
|
end
|
81
81
|
end
|
82
82
|
|
83
|
-
context
|
83
|
+
context '#update' do
|
84
84
|
before :each do
|
85
85
|
controller.stub(:interface_name, :to_sym).and_return(:user)
|
86
|
-
controller.stub(:params).and_return({:id => 1, :user =>
|
87
|
-
controller.stub(:modify => { :user =>
|
86
|
+
controller.stub(:params).and_return({:id => 1, :user => 'user' })
|
87
|
+
controller.stub(:modify => { :user => 'user' })
|
88
88
|
controller.stub(:respond_with)
|
89
89
|
controller.update
|
90
90
|
end
|
91
91
|
|
92
|
-
it
|
93
|
-
controller.instance_variable_get(
|
92
|
+
it 'should update an object' do
|
93
|
+
controller.instance_variable_get('@user').should == 'user'
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
|
-
context
|
97
|
+
context '#destroy' do
|
98
98
|
before :each do
|
99
99
|
controller.stub(:params).and_return({:id => 1})
|
100
|
-
controller.stub(:delete => { :user =>
|
100
|
+
controller.stub(:delete => { :user => 'user' })
|
101
101
|
controller.stub(:respond_with)
|
102
102
|
controller.destroy
|
103
103
|
end
|
104
104
|
|
105
|
-
it
|
106
|
-
controller.instance_variable_get(
|
105
|
+
it 'should destroy an object' do
|
106
|
+
controller.instance_variable_get('@user').should == 'user'
|
107
107
|
end
|
108
108
|
end
|
109
109
|
end
|
@@ -1,84 +1,84 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Zertico::Service do
|
4
4
|
let(:controller) { UserController.new }
|
5
5
|
let(:admin_controller) { Admin::UserController.new }
|
6
6
|
let(:object) { Object.new }
|
7
7
|
|
8
|
-
context
|
9
|
-
it
|
8
|
+
context 'should find the interface class' do
|
9
|
+
it 'on a non namespaced controller' do
|
10
10
|
controller.send(:interface_class).should == User
|
11
11
|
end
|
12
12
|
|
13
|
-
it
|
13
|
+
it 'on a namespaced controller' do
|
14
14
|
admin_controller.send(:interface_class).should == User
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
context
|
18
|
+
context '#all' do
|
19
19
|
before :each do
|
20
20
|
controller.stub_chain(:interface_name, :pluralize, :to_sym).and_return(:users)
|
21
21
|
controller.stub_chain(:interface_class, :all).and_return([])
|
22
22
|
end
|
23
23
|
|
24
|
-
it
|
24
|
+
it 'should return a collection of objects' do
|
25
25
|
controller.all.should == { :users => [] }
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
context
|
29
|
+
context '#build' do
|
30
30
|
before :each do
|
31
31
|
controller.stub_chain(:interface_name, :to_sym).and_return(:user)
|
32
32
|
controller.stub_chain(:interface_class, :new).and_return(object)
|
33
33
|
end
|
34
34
|
|
35
|
-
it
|
35
|
+
it 'should return a new object' do
|
36
36
|
controller.build.should == { :user => object }
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
context
|
40
|
+
context '#find' do
|
41
41
|
before :each do
|
42
42
|
controller.stub_chain(:interface_name, :to_sym).and_return(:user)
|
43
43
|
controller.stub_chain(:interface_class, :find).with(1).and_return(object)
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
46
|
+
it 'should return the specified object' do
|
47
47
|
controller.find(1).should == { :user => object }
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
context
|
51
|
+
context '#generate' do
|
52
52
|
before :each do
|
53
53
|
controller.stub_chain(:interface_name, :to_sym).and_return(:user)
|
54
54
|
controller.stub_chain(:interface_class, :create).with({}).and_return(object)
|
55
55
|
end
|
56
56
|
|
57
|
-
it
|
57
|
+
it 'should return the created object' do
|
58
58
|
controller.generate({}).should == { :user => object }
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
62
|
-
context
|
62
|
+
context '#modify' do
|
63
63
|
before :each do
|
64
64
|
controller.stub(:find).with(1).and_return({ :user => object })
|
65
65
|
object.stub(:update_attributes).with({}).and_return(true)
|
66
66
|
controller.stub_chain(:interface_name, :to_sym).and_return(:user)
|
67
67
|
end
|
68
68
|
|
69
|
-
it
|
69
|
+
it 'should return the updated object' do
|
70
70
|
controller.modify(1, {}).should == { :user => object }
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
-
context
|
74
|
+
context '#delete' do
|
75
75
|
before :each do
|
76
76
|
controller.stub(:find).with(1).and_return({ :user => object })
|
77
77
|
object.stub(:destroy).and_return(true)
|
78
78
|
controller.stub_chain(:interface_name, :to_sym).and_return(:user)
|
79
79
|
end
|
80
80
|
|
81
|
-
it
|
81
|
+
it 'should return the destroyed object' do
|
82
82
|
controller.delete(1).should == { :user => object }
|
83
83
|
end
|
84
84
|
end
|
data/zertico.gemspec
CHANGED
@@ -6,18 +6,17 @@ require 'zertico/version'
|
|
6
6
|
Gem::Specification.new do |gem|
|
7
7
|
gem.name = "zertico"
|
8
8
|
gem.version = Zertico::VERSION
|
9
|
-
gem.authors = [
|
10
|
-
gem.email = [
|
9
|
+
gem.authors = ['Paulo Henrique Lopes Ribeiro']
|
10
|
+
gem.email = ['plribeiro3000@gmail.com']
|
11
11
|
gem.description = %q{Easy Rails development using the Zertico Way}
|
12
12
|
gem.summary = %q{Models and patterns used by Zertico}
|
13
|
-
gem.homepage = ""
|
14
13
|
|
15
14
|
gem.files = `git ls-files`.split($/)
|
16
15
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
-
gem.require_paths = [
|
16
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features|gemfiles)/})
|
17
|
+
gem.require_paths = ['lib']
|
19
18
|
|
20
|
-
gem.add_runtime_dependency
|
21
|
-
gem.add_development_dependency
|
22
|
-
gem.add_development_dependency
|
23
|
-
end
|
19
|
+
gem.add_runtime_dependency 'rails'
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
gem.add_development_dependency 'coveralls'
|
22
|
+
end
|
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: 0.3.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-05
|
12
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -78,19 +78,22 @@ files:
|
|
78
78
|
- gemfiles/Gemfile.rails3.1
|
79
79
|
- gemfiles/Gemfile.rails3.2
|
80
80
|
- lib/zertico.rb
|
81
|
+
- lib/zertico/accessor.rb
|
81
82
|
- lib/zertico/controller.rb
|
82
83
|
- lib/zertico/service.rb
|
83
84
|
- lib/zertico/version.rb
|
84
85
|
- spec/fake_app/admin/user_controller.rb
|
85
86
|
- spec/fake_app/admin/user_service.rb
|
86
87
|
- spec/fake_app/user.rb
|
88
|
+
- spec/fake_app/user_accessor.rb
|
87
89
|
- spec/fake_app/user_controller.rb
|
88
90
|
- spec/fake_app/user_service.rb
|
89
91
|
- spec/spec_helper.rb
|
92
|
+
- spec/zertico/accessor_spec.rb
|
90
93
|
- spec/zertico/controller_spec.rb
|
91
94
|
- spec/zertico/service_spec.rb
|
92
95
|
- zertico.gemspec
|
93
|
-
homepage:
|
96
|
+
homepage:
|
94
97
|
licenses: []
|
95
98
|
post_install_message:
|
96
99
|
rdoc_options: []
|
@@ -104,7 +107,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
104
107
|
version: '0'
|
105
108
|
segments:
|
106
109
|
- 0
|
107
|
-
hash:
|
110
|
+
hash: 1292267407537345106
|
108
111
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
112
|
none: false
|
110
113
|
requirements:
|
@@ -113,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
116
|
version: '0'
|
114
117
|
segments:
|
115
118
|
- 0
|
116
|
-
hash:
|
119
|
+
hash: 1292267407537345106
|
117
120
|
requirements: []
|
118
121
|
rubyforge_project:
|
119
122
|
rubygems_version: 1.8.25
|
@@ -121,11 +124,15 @@ signing_key:
|
|
121
124
|
specification_version: 3
|
122
125
|
summary: Models and patterns used by Zertico
|
123
126
|
test_files:
|
127
|
+
- gemfiles/Gemfile.rails3.1
|
128
|
+
- gemfiles/Gemfile.rails3.2
|
124
129
|
- spec/fake_app/admin/user_controller.rb
|
125
130
|
- spec/fake_app/admin/user_service.rb
|
126
131
|
- spec/fake_app/user.rb
|
132
|
+
- spec/fake_app/user_accessor.rb
|
127
133
|
- spec/fake_app/user_controller.rb
|
128
134
|
- spec/fake_app/user_service.rb
|
129
135
|
- spec/spec_helper.rb
|
136
|
+
- spec/zertico/accessor_spec.rb
|
130
137
|
- spec/zertico/controller_spec.rb
|
131
138
|
- spec/zertico/service_spec.rb
|