param_check 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/README.md +24 -7
- data/config/locales/en.yml +4 -2
- data/lib/param_check/version.rb +1 -1
- data/lib/param_check.rb +38 -19
- data/param_check.gemspec +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9590fa4308abf4f64a13849ab47ad1dc8b68925
|
4
|
+
data.tar.gz: e857e2a0ac155531ca16253dc2d741b971e3f982
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de94c96397f07a7e6c331b421a0597c970b1e427dcd600c8b9748077da32f96ce41ffa7fbe5ed1ea4c3541320378d16fd7dfb8b2c9367fe8367449a1a1b1ba9a
|
7
|
+
data.tar.gz: 50a8a7ecf47a2afddcf592abb91083ef05bf4278bd14402157853450c9ca5eeef862c2607ed152dc3615661b78e357f8cbf13c35ab1f79167b2a964b32f9fa29
|
data/.DS_Store
ADDED
Binary file
|
data/README.md
CHANGED
@@ -68,10 +68,15 @@ params[:foo] = {
|
|
68
68
|
params[:foo] = 'bar'
|
69
69
|
```
|
70
70
|
|
71
|
-
### Validating
|
71
|
+
### Validating numbers
|
72
|
+
For number validation, you can use either the long hand keys `less_than` or the short hand `lt`
|
73
|
+
|
72
74
|
```ruby
|
73
75
|
def index
|
74
|
-
param! :foo,
|
76
|
+
param! :foo, lt: 2
|
77
|
+
param! :bar, lte: 3
|
78
|
+
param! :baz, mt: 4
|
79
|
+
param! :bazzy, mte: 5
|
75
80
|
end
|
76
81
|
```
|
77
82
|
|
@@ -79,6 +84,8 @@ end
|
|
79
84
|
```ruby
|
80
85
|
def index
|
81
86
|
param! :foo, in: ['foo', 'bar']
|
87
|
+
param! :bar, in: 1..4
|
88
|
+
param! :baz, in: 'a'..'z'
|
82
89
|
end
|
83
90
|
```
|
84
91
|
|
@@ -93,11 +100,21 @@ end
|
|
93
100
|
```
|
94
101
|
|
95
102
|
## Options
|
96
|
-
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
103
|
+
<<<<<<< HEAD
|
104
|
+
| Option | Type | Default | Values | Description |
|
105
|
+
| -------- | ------- | ------- | ---------------------------------------------------- | --------------------------------------------------- |
|
106
|
+
| required | Boolean | false | true/false | Is the parameter required? |
|
107
|
+
| type | Class | nil | Fixnum/Integer/Float/String/ActionController::Params | Specifies the type the parameter should be |
|
108
|
+
| lt | Integer | nil | Integer/Float | The parameter value should be less than |
|
109
|
+
| lte | Integer | nil | Integer/Float | The parameter value should be less than or equal to |
|
110
|
+
| mt | Integer | nil | Integer/Float | The parameter value should be more than |
|
111
|
+
| mte | Integer | nil | Integer/Float | The parameter value should be more than or equal to |
|
112
|
+
| in | Array | nil | Array | An array of values the param should match |
|
113
|
+
|
114
|
+
## Production sites using this gem
|
115
|
+
Submit a PR to add your site to the list
|
116
|
+
|
117
|
+
[Givey](https://www.givey.com)
|
101
118
|
|
102
119
|
## Development
|
103
120
|
|
data/config/locales/en.yml
CHANGED
@@ -2,6 +2,8 @@ en:
|
|
2
2
|
param_check:
|
3
3
|
missing_required_parameter: "Missing required parameter: %{parameter}"
|
4
4
|
invalid_parameter: "Parameter %{parameter} is invalid. Expected %{expected}, got %{got}"
|
5
|
-
invalid_minimum: "Parameter %{parameter} must be at least %{min}, got %{got}"
|
6
|
-
invalid_maximum: "Parameter %{parameter} must not be more than %{max}, got %{got}"
|
7
5
|
invalid_inclusion: "Parameter %{parameter} is not in the list. Expected inclusion in %{expected}, got %{got}"
|
6
|
+
value_not_less_than: "Parameter %{parameter} should be less than %{expected}. Got %{got}"
|
7
|
+
value_not_less_than_equal_to: "Parameter %{parameter} should be less than or equal to %{expected}. Got %{got}"
|
8
|
+
value_not_more_than: "Parameter %{parameter} should be more than %{expected}. Got %{got}"
|
9
|
+
value_not_more_than_equal_to: "Parameter %{parameter} should be more than or equal to %{expected}. Got %{got}"
|
data/lib/param_check/version.rb
CHANGED
data/lib/param_check.rb
CHANGED
@@ -78,27 +78,46 @@ module ParamCheck
|
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
|
-
def
|
82
|
-
if
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
81
|
+
def validate_number name, value, options = {}
|
82
|
+
options[:lt] = options[:less_than] if options[:less_than].present?
|
83
|
+
options[:lte] = options[:less_than_equal_to] if options[:less_than_equal_to].present?
|
84
|
+
options[:mt] = options[:more_than] if options[:more_than].present?
|
85
|
+
options[:more_than_equal_to] = options[:more_than_equal_to] if options[:more_than_equal_to].present?
|
86
|
+
|
87
|
+
if options[:lt].present?
|
88
|
+
raise ParameterError, I18n.t(
|
89
|
+
'param_check.value_not_less_than',
|
90
|
+
parameter: name,
|
91
|
+
expected: options[:lt],
|
92
|
+
got: value,
|
93
|
+
) if value >= options[:lt]
|
91
94
|
end
|
92
95
|
|
93
|
-
if
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
96
|
+
if options[:lte].present?
|
97
|
+
raise ParameterError, I18n.t(
|
98
|
+
'param_check.value_not_less_than_equal_to',
|
99
|
+
parameter: name,
|
100
|
+
expected: options[:lte],
|
101
|
+
got: value,
|
102
|
+
) if value > options[:lte]
|
103
|
+
end
|
104
|
+
|
105
|
+
if options[:mt].present?
|
106
|
+
raise ParameterError, I18n.t(
|
107
|
+
'param_check.value_not_more_than',
|
108
|
+
parameter: name,
|
109
|
+
expected: options[:mt],
|
110
|
+
got: value,
|
111
|
+
) if value <= options[:mt]
|
112
|
+
end
|
113
|
+
|
114
|
+
if options[:mte].present?
|
115
|
+
raise ParameterError, I18n.t(
|
116
|
+
'param_check.value_not_more_than_equal_to',
|
117
|
+
parameter: name,
|
118
|
+
expected: options[:mte],
|
119
|
+
got: value,
|
120
|
+
) if value < options[:mte]
|
102
121
|
end
|
103
122
|
end
|
104
123
|
|
data/param_check.gemspec
CHANGED
@@ -11,7 +11,7 @@ Gem::Specification.new do |spec|
|
|
11
11
|
|
12
12
|
spec.summary = %q{Validate parameters for Rails API methods}
|
13
13
|
spec.description = %q{Validate parameters presence and type for Rails API methods}
|
14
|
-
spec.homepage = "https://cjmarkham
|
14
|
+
spec.homepage = "https://github.com/cjmarkham/param_check"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: param_check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- cjmarkham
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -73,6 +73,7 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- ".DS_Store"
|
76
77
|
- ".gitignore"
|
77
78
|
- ".rspec"
|
78
79
|
- CODE_OF_CONDUCT.md
|
@@ -88,7 +89,7 @@ files:
|
|
88
89
|
- lib/param_check/engine.rb
|
89
90
|
- lib/param_check/version.rb
|
90
91
|
- param_check.gemspec
|
91
|
-
homepage: https://cjmarkham
|
92
|
+
homepage: https://github.com/cjmarkham/param_check
|
92
93
|
licenses:
|
93
94
|
- MIT
|
94
95
|
metadata: {}
|