digget 0.1.0 → 0.1.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: 844819201cdd222faf30bdd0b8abf0cc2a63b24c
4
- data.tar.gz: 71c0f7d24f13af6fdc051f925da254902d1a9e6f
3
+ metadata.gz: de08739753470f3086606f6ffeafd94653130f70
4
+ data.tar.gz: 44fea04690dc6eba3f91a20d9a73cc29c21fbe86
5
5
  SHA512:
6
- metadata.gz: 6f88cfb2e064c08028ef62d7e72a976e905b2dbdabe509772e66778bd9626d0bb5a58be3d7b4e7e0111a41165cab365a5cd23b686db42e3f026176470681bd1d
7
- data.tar.gz: 13aeb6030bc94ca3d26d58059e86ec0c209d6e79278fa5b29506360761e8c87b29cce1a788f342f7a4039891b4f3261af09ffce6c44fce310866bcf73c232b65
6
+ metadata.gz: ee5da6726acb144c7c9debf87fd97f5af7b822c4b22dde2a73d57d2fc4b816e6be7e177debe91532b5c8d45816ee01c034f3afd8f4131a5cfdf06605f30b2c5c
7
+ data.tar.gz: b2d83a9c3ad1b3e116524f1aaa09c557c65c74d892c79804a4fa6ba79d06fa5dc4913a6a047dd7ac68dfce15c30f9a93b07c5f31d12509eb9919aa50663b03fc
data/README.md CHANGED
@@ -1,10 +1,55 @@
1
1
  [![codecov](https://codecov.io/gh/pielambr/digget/branch/master/graph/badge.svg)](https://codecov.io/gh/pielambr/digget)
2
2
  [![Build Status](https://travis-ci.org/pielambr/digget.svg?branch=master)](https://travis-ci.org/pielambr/digget)
3
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/2351e4afa1f24e16af9c576bc619ea40)](https://www.codacy.com/app/pielambr/digget?utm_source=github.com&utm_medium=referral&utm_content=pielambr/digget&utm_campaign=Badge_Grade)
4
+ [![Gem Version](https://badge.fury.io/rb/digget.svg)](https://badge.fury.io/rb/digget)
3
5
  # Digget
4
- Short description and motivation.
6
+ This gem aims to make for an easier search API by validating incoming parameters and filtering your model accordingly.
5
7
 
8
+ **Note**: this gem is under _very early_ development and is not finished in any way
6
9
  ## Usage
7
- How to use my plugin.
10
+ ### Validating of parameters
11
+ The only thing you have to do is extends the Validator class, so you can use the `verify` method.
12
+ ```ruby
13
+ class YourValidator < Digget::Validator
14
+ def validate_id_params
15
+ verify :id, Integer, max: 100, min: 50
16
+ end
17
+
18
+ def validate_search_params
19
+ verify :name, String, required: true
20
+ verify :size, Float, required: true, min: 15
21
+ end
22
+ end
23
+ ```
24
+ To validate the `params` you need to run the validator;
25
+ ```ruby
26
+ validator = YourValidator.new(params)
27
+ validator.validate_id_params
28
+ ```
29
+ You can then see if there are any errors during validation
30
+ ```ruby
31
+ validator.errors
32
+ ```
33
+ You can also get a Hash with the parameters casted to the right datatype
34
+ ```ruby
35
+ validator.casted_params
36
+ ```
37
+ #### Supported datatypes
38
+ - Float
39
+ - Integer
40
+ - String
41
+ - Date
42
+ - Time
43
+ #### Supported validation options
44
+ All of the following options can be combined
45
+ - **required** (checks whether the parameter is present)
46
+ - **min** (checks whether the parameter is larger than the provided value)
47
+ - **max** (checks whether the parameter is lower than the provided value)
48
+ - **min_length** (checks whether the parameter is longer than this)
49
+ - **max_length** (checks whether the parameter is shorter than this)
50
+ - **length** (checks whether the parameter has this exact length)
51
+ - **equal** (check whether the parameter is equal to the provided value)
52
+ - **not_equal** (checks whether the parameter is not equal to the provided value)
8
53
 
9
54
  ## Installation
10
55
  Add this line to your application's Gemfile:
@@ -23,8 +68,5 @@ Or install it yourself as:
23
68
  $ gem install digget
24
69
  ```
25
70
 
26
- ## Contributing
27
- Contribution directions go here.
28
-
29
71
  ## License
30
72
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -83,6 +83,12 @@ module Digget
83
83
  elsif key == :max && !param.nil?
84
84
  next unless param > value
85
85
  @errors.append(I18n.t('digget.max', name: name, value: value))
86
+ elsif key == :equal && !param.nil
87
+ next unless param != value
88
+ @errors.append(I18n.t('digget.equal', name: name, value: value))
89
+ elsif key == :not_equal && !param.nil
90
+ next unless param == value
91
+ @errors.append(I18n.t('digget.not_equal', name: name, value: value))
86
92
  elsif key == :min_length && !param.nil?
87
93
  next unless param.length < value
88
94
  @errors.append(I18n.t('digget.min_length', name: name, value: value))
@@ -1,3 +1,3 @@
1
1
  module Digget
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -6,4 +6,6 @@ en:
6
6
  max: "The parameter `%{name}` can be %{value} at most"
7
7
  min_length: "The parameter `%{name}` should have a length of at least %{value}"
8
8
  max_length: "The parameter `%{name}` should have a length of %{value} at most"
9
- length: "The parameter `%{name}` should have a length of %{value}"
9
+ length: "The parameter `%{name}` should have a length of %{value}"
10
+ equal: "The parameter `%{name}` should have be equal to %{value}"
11
+ not_equal: "The parameter `%{name}` should not be equal to %{value}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: digget
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pieterjan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-10-21 00:00:00.000000000 Z
11
+ date: 2017-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -108,7 +108,8 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description: Description of Digget.
111
+ description: Digget makes creating search endpoints easier. It allows you to put some
112
+ validations on incoming parameters and use these parameters to filter models.
112
113
  email:
113
114
  - me@pielambr.be
114
115
  executables: []
@@ -123,7 +124,7 @@ files:
123
124
  - lib/digget/version.rb
124
125
  - lib/tasks/digget_tasks.rake
125
126
  - lib/translations/digget.yml
126
- homepage: https://www.pielambr.be
127
+ homepage: https://github.com/pielambr/digget
127
128
  licenses:
128
129
  - MIT
129
130
  metadata: {}
@@ -146,5 +147,5 @@ rubyforge_project:
146
147
  rubygems_version: 2.6.12
147
148
  signing_key:
148
149
  specification_version: 4
149
- summary: Summary of Digget.
150
+ summary: Easy parameter validation and model filtering.
150
151
  test_files: []