sinatra-strong-params 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0c3d5236e9fcbd2d878573d2e04dbdef15b7df3
4
- data.tar.gz: 300ef2e3e4cf32ab6d55f0fbbfe839dc647110ca
3
+ metadata.gz: d7e198ec2d712488f1d5ae9e05c578e7a0cf52da
4
+ data.tar.gz: 6ed634ad02a939f12ddb34af2851e8f248ae8df4
5
5
  SHA512:
6
- metadata.gz: 0f99cc84b7b4145cffeafbc6510add4ada732befcb7d466c5155942b3af48afdd163b6fcc4ee0a44ccef0dd70d1bbc523326c03d16b094891ff341ca1c21ed85
7
- data.tar.gz: 676ee9e458fff1d5b253c7102f9d8e2822d7dbdb4d661ef53a2aa61ee1004a5d11ef970977f34f4412349deb894215f86bb4f7e20865e9598117ce7d7c8092f9
6
+ metadata.gz: b9aa465bc866fababaa1f807f6bc04397a139a531dc3714e3c6ca4847bb533eb1c3f313a90132b3d4fdd4089a15dd7b99a6fc69a18b7b2a4f739064c631dce49
7
+ data.tar.gz: 929441a2c4be7f6954f985e3ead0f9ae853862d6922f405175b2adab91169aef82e37acc6bc68dee68695881d59db0b65fb3d6ffb3091c8bd0c5101bacb6c333
data/README.md CHANGED
@@ -18,7 +18,11 @@ Or install it yourself as:
18
18
 
19
19
  $ gem install sinatra-strong-params
20
20
 
21
+ If you are using a Modular Sinatra application such as `class FooApp < Sinatra::Base` you must include any desired extensions explicitly within your Sinatra application
21
22
 
23
+ ```ruby
24
+ register Sinatra::StrongParams
25
+ ```
22
26
 
23
27
  ## Usage
24
28
 
@@ -63,6 +67,18 @@ end
63
67
  ```
64
68
 
65
69
 
70
+
71
+ ### Both
72
+
73
+ Wanna get super restrictive? Can do.
74
+
75
+ ```ruby
76
+ post '/login', allows: [:email, :password], needs: [:email, :password] do
77
+ # handle yo business
78
+ end
79
+ ```
80
+
81
+
66
82
  ## Contributing
67
83
 
68
84
  1. Fork it ( https://github.com/[my-github-username]/sinatra-strong-params/fork )
@@ -18,13 +18,13 @@ module Sinatra
18
18
  #
19
19
  app.set(:allows) do |*passable|
20
20
  condition do
21
- unless @params.blank?
21
+ unless @params.empty?
22
22
  @_params = @_params || @params # for safety
23
23
  globals = settings.globally_allowed_parameters
24
24
  passable = (globals | passable).map(&:to_sym) # make sure it's a symbol
25
25
 
26
26
  # trim the params down
27
- @params = @params.select do |param, value|
27
+ @params = @params.select do |param, _value|
28
28
  passable.include?(param.to_sym)
29
29
  end
30
30
  end
@@ -44,9 +44,8 @@ module Sinatra
44
44
  app.set(:needs) do |*needed|
45
45
  condition do
46
46
  if @params.nil? || @params.empty? && !needed.empty?
47
- raise RequiredParamMissing, 'One or more required parameters were missing.'
47
+ fail RequiredParamMissing, settings.missing_parameter_message
48
48
  else
49
- @_params = @_params || @params # for safety
50
49
  needed = needed.map(&:to_sym) # make sure it's a symbol
51
50
  sym_params = @params.dup
52
51
 
@@ -56,18 +55,28 @@ module Sinatra
56
55
  end
57
56
 
58
57
  if needed.any? { |key| sym_params[key].nil? || sym_params[key].empty? }
59
- raise RequiredParamMissing, 'One or more required parameters were missing.'
58
+ fail RequiredParamMissing, settings.missing_parameter_message
60
59
  end
61
60
  end
62
61
  end
63
62
  end
64
63
 
65
- # these will always pass through the 'allows' method
66
- # and will be mapped to symbols. I often use ['redirect_to', '_csrf'] here
67
- # because I always want them to pass through for later processing
64
+ # These will always pass through the 'allows' method
65
+ # and will be mapped to symbols. I often use [:redirect_to, :_csrf] here
66
+ # because I always want them to pass through for later processing
68
67
  app.set :globally_allowed_parameters, []
69
68
 
70
- # default error response
69
+ # The default message when RequiredParamMissing is raised.
70
+ app.set :missing_parameter_message, 'One or more required parameters were missing.'
71
+
72
+ # Change the default behavior for missing parameters by overriding this route.
73
+ # For example...
74
+ #
75
+ # error RequiredParamMissing do
76
+ # flash[:error] = env['sinatra.error'].message
77
+ # redirect back
78
+ # end
79
+ #
71
80
  app.error RequiredParamMissing do
72
81
  [400, env['sinatra.error'].message]
73
82
  end
@@ -1,5 +1,5 @@
1
1
  module Sinatra
2
2
  module StrongParams
3
- VERSION = "0.0.1"
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-strong-params
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Lecklider
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-12 00:00:00.000000000 Z
11
+ date: 2015-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: 1.4.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.4.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.6'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.6'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Some super basic strong parameter filters for Sinatra.
@@ -59,7 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
62
+ - ".gitignore"
63
63
  - Gemfile
64
64
  - LICENSE.txt
65
65
  - README.md
@@ -77,17 +77,17 @@ require_paths:
77
77
  - lib
78
78
  required_ruby_version: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  required_rubygems_version: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - '>='
85
+ - - ">="
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  requirements: []
89
89
  rubyforge_project:
90
- rubygems_version: 2.3.0
90
+ rubygems_version: 2.4.8
91
91
  signing_key:
92
92
  specification_version: 4
93
93
  summary: Some super basic strong parameter filters for Sinatra.