case_sensitive_attributes 0.1.0 → 0.2.1
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,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41e13e8657a9c966b609884569dac9413fcba17e
|
4
|
+
data.tar.gz: e50c8be43d9a5a2eefb0765e4b087de3f15b4585
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1db2812ff3326d83d09132dc7831a595fc6f4ac3e6e686024541fb1b2bb3d6d4f3a5f166d35524417a59181512a463b546c9cd0bfff841ace879d70b2472333c
|
7
|
+
data.tar.gz: a6050fb6beec372420013ca65b33dd13dcc90f908c8fa4f222350f678bb6b3bf7e439188b07a8cc8f19357067b24152c7951a98f46950bd1c890c24c6e7fc84f
|
data/README.md
CHANGED
@@ -28,3 +28,18 @@ end
|
|
28
28
|
```
|
29
29
|
>- allow kinds:
|
30
30
|
[:capitalize, :downcase, :upcase]
|
31
|
+
|
32
|
+
|
33
|
+
##### Set kinds for your params (form params or query string)
|
34
|
+
|
35
|
+
```ruby
|
36
|
+
module Dummy
|
37
|
+
class Application < Rails::Application
|
38
|
+
config.middleware.insert_after ActionDispatch::ParamsParser, CaseSensitiveAttributes::Middleware do
|
39
|
+
#params attribute: :kind
|
40
|
+
params email: :downcase
|
41
|
+
end
|
42
|
+
end
|
43
|
+
```
|
44
|
+
>- allow kinds:
|
45
|
+
[:capitalize, :downcase, :upcase]
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module CaseSensitiveAttributes
|
2
|
+
class Middleware
|
3
|
+
|
4
|
+
def initialize(app, opts={}, &block)
|
5
|
+
@app = app
|
6
|
+
instance_eval(&block) if block_given?
|
7
|
+
end
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
request = Rack::Request.new(env)
|
11
|
+
|
12
|
+
replace(request.GET) if request.GET.present?
|
13
|
+
replace(request.POST) if request.POST.present?
|
14
|
+
|
15
|
+
@app.call(env)
|
16
|
+
end
|
17
|
+
|
18
|
+
def params(options={})
|
19
|
+
@params = options
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def replace(hash)
|
25
|
+
transform(hash).each { |key, value| hash[key] = value }
|
26
|
+
end
|
27
|
+
|
28
|
+
def transform(hash)
|
29
|
+
hash.each do |key, value|
|
30
|
+
if value.is_a?(Hash)
|
31
|
+
hash[key] = transform(value)
|
32
|
+
elsif @params.keys.include?(key.to_sym)
|
33
|
+
hash[key] = Transformer.call(value, @params[key.to_sym])
|
34
|
+
else
|
35
|
+
hash[key] = value
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -1,26 +1,26 @@
|
|
1
1
|
module CaseSensitiveAttributes
|
2
2
|
class Transformer
|
3
3
|
|
4
|
-
|
4
|
+
def self.call(value, kind)
|
5
5
|
new(value, kind).call
|
6
|
-
|
6
|
+
end
|
7
7
|
|
8
8
|
def initialize(value, kind)
|
9
|
-
|
10
|
-
|
9
|
+
@value = value
|
10
|
+
@kind = kind.to_sym
|
11
11
|
end
|
12
12
|
|
13
13
|
def call
|
14
|
-
|
15
|
-
|
14
|
+
raise CaseSensitiveAttributes::IncorrectKind.new("Your kind (#{kind}) is not correct.") if whitelist.exclude?(kind)
|
15
|
+
value.present? ? value.to_s.send(kind) : value
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
20
|
attr_reader :value, :kind
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
22
|
+
def whitelist
|
23
|
+
[:capitalize, :downcase, :upcase]
|
24
|
+
end
|
25
25
|
end
|
26
26
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require "case_sensitive_attributes/version"
|
2
2
|
require "case_sensitive_attributes/incorrect_kind"
|
3
3
|
require "case_sensitive_attributes/transformer"
|
4
|
+
require "case_sensitive_attributes/middleware"
|
4
5
|
|
5
6
|
module CaseSensitiveAttributes
|
6
7
|
def case_sensitive_attributes(params)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: case_sensitive_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damian Śliwecki
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02
|
11
|
+
date: 2016-03-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- case_sensitive_attributes.gemspec
|
114
114
|
- lib/case_sensitive_attributes.rb
|
115
115
|
- lib/case_sensitive_attributes/incorrect_kind.rb
|
116
|
+
- lib/case_sensitive_attributes/middleware.rb
|
116
117
|
- lib/case_sensitive_attributes/transformer.rb
|
117
118
|
- lib/case_sensitive_attributes/version.rb
|
118
119
|
homepage: https://github.com/sliwecki/case_sensitive_attributes
|
@@ -135,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
136
|
version: '0'
|
136
137
|
requirements: []
|
137
138
|
rubyforge_project:
|
138
|
-
rubygems_version: 2.
|
139
|
+
rubygems_version: 2.6.1
|
139
140
|
signing_key:
|
140
141
|
specification_version: 4
|
141
142
|
summary: Case sensitive for attributes
|