cyrax 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YmU2Yjk4MDY1NjM4YzEyZDRlYTUzNWEwOTc0MWI3MmUzMzk0YTA1Mw==
4
+ YzRmM2U4Y2E4NDA2Y2E3YWQ5ZTFkZGEzZmQ3ZWZhMjdmYTY4NWM2Yw==
5
5
  data.tar.gz: !binary |-
6
- YTBkY2Q5MDljMGEwMmYzZWFjNzJjNTdjNjM4MDI0MzIzOTg2ODAwZQ==
6
+ NjcyODNjMjYwZDJlNzI5MzBlMWNkNTAwNTM0OGEwYmNhNjg2OTlmZg==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- MTMwNjQ5MDljODVjMzA5YjM0NWExYzBhNjZmZDcwMTZhMTRjOWMyZGFhNzYy
10
- ZmFkNTY0YzBiMDhhMjllZGIxODI5MzVhOGExNzZkNGNhZDgyN2U0YjQwNjYy
11
- MDExNDQ3NGUzY2IzNjcyY2Q5Nzk3MWJiMDE5MWUyMzUyOTU3ODA=
9
+ ZDZkMDFhNThmYTBhYTQ5YWVkYTBjYzdmZmQ4MDc1ZDYzMmU3MGI3YWQ4NWQ2
10
+ ZWJiNWI5MTc1MTAwZjNkZjIyMDMxMTFhN2RmMmE0M2ZmYmFjZmExMWNhNGNh
11
+ MjcwOWM4NTM4ZmNjOGJiMWQyNTVlNGI3NmEwZmJjOTE0MWIwYTk=
12
12
  data.tar.gz: !binary |-
13
- MDc4MWM2ZDFmNWEyNWQ4YjE0MDEwMzkyODdlMjliN2JlZGVkZGZlMjkyMjI0
14
- YTk5YjIzYzFmMWEwN2VkMWU3ODU0OGRhYTQ1MTE5ZDJjNjVhYTJkMjAwYzJk
15
- ZmIxOGFlYTRiMzkwNGE4ZTFhOWRmNzVmNDhjZGM4MDYxZDAyNzI=
13
+ MmIxNjFkMzM0ZWU2MWQ4NjBlOWQzYjRiYjRmYTk1OTVmYjlhNDZiNTI2NTEy
14
+ ZDNlNmNmZGUwM2M3OTczYWU4MmRjZWQwYmQ4NDI0MDExNjcwNGE2MDRkY2Ni
15
+ NmMyOTI4ZThjN2M2OWU2NGVjZWRmMWY5OWI0YzM0MDFlN2I1Mzc=
@@ -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 params.respond_to?(:require)
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 attributes.respond_to?(:permit)
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
- if !Cyrax.strong_parameters && self.class.accessible_attributes.blank?
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
@@ -1,3 +1,3 @@
1
1
  module Cyrax
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -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
- subject.send(:filter_attributes, {foo: 'bar'}).should eq({})
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cyrax
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Droidlabs