cyrax 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/cyrax/extensions/has_repository.rb +5 -5
- data/lib/cyrax/extensions/has_service.rb +10 -24
- data/lib/cyrax/version.rb +1 -1
- data/spec/cyrax/resource_spec.rb +4 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OGI2YjFjYzU3ZDA4OGJlOTNjMWQzNjcxMDMwMzYzODM3ZmRhNTVhNQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDZjNzE5ZTM2NTAxMjI2MjllOWIyOWQ5NDk4NTQ5ZWNhYTBiYWRlZA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YjZmOTc3OWE5MWExZmEyYmMyMTkwNGUxNDNmYzZmZjEzMTU0NWVjMTEyNTQ5
|
10
|
+
NmZkMDQxZDI1YWMxMTIyMjhhMTFlODZlZjJiYjhjMmFjYTc4YzNjZDE1MGNh
|
11
|
+
YjA4OWRiZDhiYWEzZGM0Mjc2NGVkYTNlNGM1ZjA4MjIxMWYyMDM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZTQ5YWM4NTczOTk2N2M0YzUzZDUwMWMyNWRjZmIxZDUwYWRiMzI2YzNmZjZi
|
14
|
+
Yzg4ZWNjYjVjYjA1YTE4NDY4OTk5YjZiMzk1NDczYWQ5ODc3NTJhY2I0YWRj
|
15
|
+
ZTZiNjAyMWYxOTRjNjE2MTIyOGIyNDIzMzg3NDYzYzNmNWFmOTM=
|
@@ -19,6 +19,10 @@ module Cyrax::Extensions
|
|
19
19
|
end
|
20
20
|
|
21
21
|
module ClassMethods
|
22
|
+
def inherited(subclass)
|
23
|
+
subclass._repository_options = self._repository_options.try(:clone)
|
24
|
+
end
|
25
|
+
|
22
26
|
def repository(name = nil, &block)
|
23
27
|
if name.is_a?(Symbol)
|
24
28
|
klass, finder_name = nil, name
|
@@ -33,11 +37,7 @@ module Cyrax::Extensions
|
|
33
37
|
self._repository_class = klass
|
34
38
|
end
|
35
39
|
if block_given?
|
36
|
-
|
37
|
-
if self._repository_options.present?
|
38
|
-
self._repository_options = self._repository_options.dup
|
39
|
-
end
|
40
|
-
|
40
|
+
self._repository_options = self._repository_options.try(:clone)
|
41
41
|
self._repository_options ||= {}
|
42
42
|
self._repository_options[:finders] ||= {}
|
43
43
|
self._repository_options[:finders][finder_name || :scope] = block
|
@@ -28,12 +28,14 @@ module Cyrax::Extensions
|
|
28
28
|
# Used for :create action in controller
|
29
29
|
# @return [Cyrax::Response] response
|
30
30
|
def create(custom_attributes = nil, &block)
|
31
|
-
resource = repository.build(nil
|
31
|
+
resource = repository.build(nil)
|
32
|
+
old_resource = resource.dup
|
33
|
+
set_resource_attributes(resource, custom_attributes||resource_attributes)
|
32
34
|
authorize_resource!(:create, resource)
|
33
35
|
transaction do
|
34
36
|
if repository.save(resource)
|
35
37
|
set_message(:created)
|
36
|
-
block.call(resource) if block_given?
|
38
|
+
block.call(resource, old_resource) if block_given?
|
37
39
|
end
|
38
40
|
end
|
39
41
|
respond_with(resource)
|
@@ -56,12 +58,14 @@ module Cyrax::Extensions
|
|
56
58
|
# Used for :update action in controller
|
57
59
|
# @return [Cyrax::Response] response
|
58
60
|
def update(custom_attributes = nil, &block)
|
59
|
-
resource = repository.build(resource_params_id
|
61
|
+
resource = repository.build(resource_params_id)
|
62
|
+
old_resource = resource.dup
|
63
|
+
set_resource_attributes(resource, custom_attributes||resource_attributes)
|
60
64
|
authorize_resource!(:update, resource)
|
61
65
|
transaction do
|
62
66
|
if repository.save(resource)
|
63
67
|
set_message(:updated)
|
64
|
-
block.call(resource) if block_given?
|
68
|
+
block.call(resource, old_resource) if block_given?
|
65
69
|
end
|
66
70
|
end
|
67
71
|
respond_with(resource)
|
@@ -105,26 +109,8 @@ module Cyrax::Extensions
|
|
105
109
|
params[:id]
|
106
110
|
end
|
107
111
|
|
108
|
-
|
109
|
-
|
110
|
-
ActiveSupport::Deprecation.warn "#resource_scope inside Resource deprecated. Use repository.scope instead."
|
111
|
-
repository.scope
|
112
|
-
end
|
113
|
-
def build_collection
|
114
|
-
ActiveSupport::Deprecation.warn "#build_collection inside Resource deprecated. Use repository.find_all instead."
|
115
|
-
repository.find_all
|
116
|
-
end
|
117
|
-
def find_resource(id)
|
118
|
-
ActiveSupport::Deprecation.warn "#find_resource inside Resource deprecated. Use repository.find instead."
|
119
|
-
repository.find(id)
|
120
|
-
end
|
121
|
-
def save_resource(resource)
|
122
|
-
ActiveSupport::Deprecation.warn "#save_resource inside Resource deprecated. Use repository.save instead."
|
123
|
-
repository.save(resource)
|
124
|
-
end
|
125
|
-
def delete_resource(resource)
|
126
|
-
ActiveSupport::Deprecation.warn "#delete_resource inside Resource deprecated. Use repository.delete instead."
|
127
|
-
repository.delete(resource)
|
112
|
+
def set_resource_attributes(resource, attributes = {})
|
113
|
+
resource.attributes = attributes
|
128
114
|
end
|
129
115
|
end
|
130
116
|
end
|
data/lib/cyrax/version.rb
CHANGED
data/spec/cyrax/resource_spec.rb
CHANGED
@@ -77,7 +77,8 @@ module Cyrax
|
|
77
77
|
before { repository.stub(:build).and_return(resource) }
|
78
78
|
it 'responds with resource' do
|
79
79
|
repository.should_receive(:save).with(resource)
|
80
|
-
repository.should_receive(:build).with(nil
|
80
|
+
repository.should_receive(:build).with(nil)
|
81
|
+
subject.should_receive(:set_resource_attributes).with(resource, params)
|
81
82
|
subject.should_receive(:respond_with).with(resource)
|
82
83
|
subject.create(params)
|
83
84
|
end
|
@@ -105,8 +106,9 @@ module Cyrax
|
|
105
106
|
let(:params) { {foo: 'bar'} }
|
106
107
|
before { repository.stub(:build).and_return(resource) }
|
107
108
|
it 'responds with resource' do
|
108
|
-
repository.should_receive(:build).with(123
|
109
|
+
repository.should_receive(:build).with(123)
|
109
110
|
repository.should_receive(:save).with(resource)
|
111
|
+
subject.should_receive(:set_resource_attributes).with(resource, params)
|
110
112
|
subject.should_receive(:respond_with).with(resource)
|
111
113
|
subject.update(params)
|
112
114
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cyrax
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Droidlabs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -158,3 +158,4 @@ test_files:
|
|
158
158
|
- spec/cyrax/response_spec.rb
|
159
159
|
- spec/cyrax/serializer_spec.rb
|
160
160
|
- spec/spec_helper.rb
|
161
|
+
has_rdoc:
|