zertico 0.5.6 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/zertico/service.rb +17 -5
- data/lib/zertico/version.rb +2 -2
- data/spec/zertico/service_spec.rb +37 -7
- metadata +9 -3
data/lib/zertico/service.rb
CHANGED
@@ -1,19 +1,19 @@
|
|
1
1
|
module Zertico
|
2
2
|
module Service
|
3
3
|
def all
|
4
|
-
{ interface_name.pluralize.to_sym =>
|
4
|
+
{ interface_name.pluralize.to_sym => resource.all }
|
5
5
|
end
|
6
6
|
|
7
7
|
def build
|
8
|
-
{ interface_name.to_sym =>
|
8
|
+
{ interface_name.to_sym => resource.new }
|
9
9
|
end
|
10
10
|
|
11
11
|
def find(id)
|
12
|
-
{ interface_name.to_sym =>
|
12
|
+
{ interface_name.to_sym => resource.find(id) }
|
13
13
|
end
|
14
14
|
|
15
15
|
def generate(attributes = {})
|
16
|
-
{ interface_name.to_sym =>
|
16
|
+
{ interface_name.to_sym => resource.create(attributes) }
|
17
17
|
end
|
18
18
|
|
19
19
|
def modify(id, attributes = {})
|
@@ -28,6 +28,18 @@ module Zertico
|
|
28
28
|
{ interface_name.to_sym => object }
|
29
29
|
end
|
30
30
|
|
31
|
+
def resource
|
32
|
+
@resource ||= interface_class
|
33
|
+
end
|
34
|
+
|
35
|
+
def resource=(resource_chain = [])
|
36
|
+
@resource = resource_chain.shift
|
37
|
+
@resource = @resource.constantize if @resource.respond_to?(:constantize)
|
38
|
+
resource_chain.each do |resource|
|
39
|
+
@resource = @resource.send(resource)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
31
43
|
protected
|
32
44
|
|
33
45
|
def interface_name
|
@@ -42,4 +54,4 @@ module Zertico
|
|
42
54
|
end
|
43
55
|
end
|
44
56
|
end
|
45
|
-
end
|
57
|
+
end
|
data/lib/zertico/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Zertico
|
2
|
-
VERSION = '0.
|
3
|
-
end
|
2
|
+
VERSION = '0.6.0'
|
3
|
+
end
|
@@ -5,14 +5,11 @@ describe Zertico::Service do
|
|
5
5
|
let(:admin_controller) { Admin::UserController.new }
|
6
6
|
let(:profile_controller) { Person::ProfileController.new }
|
7
7
|
let(:object) { Object.new }
|
8
|
-
let(:
|
8
|
+
let(:users_controller) { UsersController.new }
|
9
9
|
|
10
|
-
context 'on a pluralized
|
10
|
+
context 'on a pluralized controller' do
|
11
11
|
it 'should find the interface model' do
|
12
|
-
|
13
|
-
end
|
14
|
-
it 'should find the interface class' do
|
15
|
-
pluralized_controller.send(:interface_class).should == User
|
12
|
+
users_controller.send(:interface_class).should == User
|
16
13
|
end
|
17
14
|
end
|
18
15
|
|
@@ -101,4 +98,37 @@ describe Zertico::Service do
|
|
101
98
|
controller.delete(1).should == { :person => object }
|
102
99
|
end
|
103
100
|
end
|
104
|
-
|
101
|
+
|
102
|
+
context '#resource' do
|
103
|
+
context 'with no resource defined' do
|
104
|
+
before :each do
|
105
|
+
controller.stub(:interface_class => User)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should return the resource' do
|
109
|
+
controller.resource.should == User
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'with a resource defined' do
|
114
|
+
before :each do
|
115
|
+
controller.resource = %w(Person::Profile)
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should return the resource' do
|
119
|
+
controller.resource.should == Person::Profile
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context '#resource=' do
|
125
|
+
before :each do
|
126
|
+
User.stub(:all => [ object ])
|
127
|
+
controller.resource = %w(User all)
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should set the resource' do
|
131
|
+
controller.resource.should == [ object ]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
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.6.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-08-
|
12
|
+
date: 2013-08-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -111,15 +111,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
111
|
- - ! '>='
|
112
112
|
- !ruby/object:Gem::Version
|
113
113
|
version: '0'
|
114
|
+
segments:
|
115
|
+
- 0
|
116
|
+
hash: -3191919241399243181
|
114
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
118
|
none: false
|
116
119
|
requirements:
|
117
120
|
- - ! '>='
|
118
121
|
- !ruby/object:Gem::Version
|
119
122
|
version: '0'
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
hash: -3191919241399243181
|
120
126
|
requirements: []
|
121
127
|
rubyforge_project:
|
122
|
-
rubygems_version: 1.8.
|
128
|
+
rubygems_version: 1.8.25
|
123
129
|
signing_key:
|
124
130
|
specification_version: 3
|
125
131
|
summary: Models and patterns used by Zertico
|