cyrax 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/cyrax.rb +8 -1
- data/lib/cyrax/extensions/has_resource.rb +5 -9
- data/lib/cyrax/version.rb +1 -1
- data/spec/cyrax/extensions/has_resource_spec.rb +8 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzRmM2U4Y2E4NDA2Y2E3YWQ5ZTFkZGEzZmQ3ZWZhMjdmYTY4NWM2Yw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjcyODNjMjYwZDJlNzI5MzBlMWNkNTAwNTM0OGEwYmNhNjg2OTlmZg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZDZkMDFhNThmYTBhYTQ5YWVkYTBjYzdmZmQ4MDc1ZDYzMmU3MGI3YWQ4NWQ2
|
10
|
+
ZWJiNWI5MTc1MTAwZjNkZjIyMDMxMTFhN2RmMmE0M2ZmYmFjZmExMWNhNGNh
|
11
|
+
MjcwOWM4NTM4ZmNjOGJiMWQyNTVlNGI3NmEwZmJjOTE0MWIwYTk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MmIxNjFkMzM0ZWU2MWQ4NjBlOWQzYjRiYjRmYTk1OTVmYjlhNDZiNTI2NTEy
|
14
|
+
ZDNlNmNmZGUwM2M3OTczYWU4MmRjZWQwYmQ4NDI0MDExNjcwNGE2MDRkY2Ni
|
15
|
+
NmMyOTI4ZThjN2M2OWU2NGVjZWRmMWY5OWI0YzM0MDFlN2I1Mzc=
|
data/lib/cyrax.rb
CHANGED
@@ -11,6 +11,13 @@ require "cyrax/callbacks.rb"
|
|
11
11
|
require "cyrax/decorator.rb"
|
12
12
|
|
13
13
|
module Cyrax
|
14
|
-
mattr_accessor :strong_parameters
|
15
14
|
@@strong_parameters = false
|
15
|
+
|
16
|
+
def self.strong_parameters
|
17
|
+
@@strong_parameters
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.strong_parameters=(value)
|
21
|
+
@@strong_parameters = value
|
22
|
+
end
|
16
23
|
end
|
@@ -64,7 +64,7 @@ module Cyrax::Extensions
|
|
64
64
|
|
65
65
|
private
|
66
66
|
def dirty_resource_attributes
|
67
|
-
if
|
67
|
+
if Cyrax.strong_parameters
|
68
68
|
params.require(resource_name)
|
69
69
|
else
|
70
70
|
params[resource_name] || {}
|
@@ -76,16 +76,12 @@ module Cyrax::Extensions
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def filter_attributes(attributes)
|
79
|
-
if
|
79
|
+
if Cyrax.strong_parameters
|
80
80
|
attributes.permit(self.class.accessible_attributes)
|
81
|
+
elsif self.class.accessible_attributes.blank?
|
82
|
+
attributes
|
81
83
|
else
|
82
|
-
|
83
|
-
attributes
|
84
|
-
else
|
85
|
-
attributes.select do |key, value|
|
86
|
-
self.class.accessible_attributes.include?(key.to_sym)
|
87
|
-
end
|
88
|
-
end
|
84
|
+
attributes.slice(*self.class.accessible_attributes)
|
89
85
|
end
|
90
86
|
end
|
91
87
|
end
|
data/lib/cyrax/version.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
+
class StrongParameters < Hash
|
4
|
+
def permit(attrs)
|
5
|
+
self.slice(*attrs)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
class Bar; end
|
4
10
|
class Foo; end
|
5
11
|
|
@@ -133,10 +139,10 @@ module Cyrax
|
|
133
139
|
end
|
134
140
|
it 'should return blank attributes by default for strong_paramters=true' do
|
135
141
|
Cyrax.strong_parameters = true
|
136
|
-
|
142
|
+
params = StrongParameters.new(foo: 'bar')
|
143
|
+
subject.send(:filter_attributes, params).should eq({})
|
137
144
|
end
|
138
145
|
end
|
139
146
|
end
|
140
|
-
|
141
147
|
end
|
142
148
|
end
|