fluent-validation 0.1.0
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 +7 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +52 -0
- data/README.md +73 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/fluent-validation.gemspec +35 -0
- data/lib/fluent/validation.rb +45 -0
- data/lib/fluent/validation/version.rb +5 -0
- metadata +125 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fad1e9ffde8705923b9edecb80f32bc4089de021
|
4
|
+
data.tar.gz: 1bd8fc5f5c8f1afe86dead92172f7a6b1b6742d8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 20c5ef9e53d3c145a58e14c934e295414daf05cc98520678aa1b30c167ee6063c274fe2246b14f2838d621e74b0b2de66a728ac0b0f07bf2634b7f9c2e42dc1c
|
7
|
+
data.tar.gz: 6177136f7325157e3117ca91cd0134e5003c1a68c36e648fe0d6929da4fc48a495e02455e6f0051a11e20df8b630189b48cc837812b26b2fb9e9459a9ee19e8a
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
fluent-validation (0.1.0)
|
5
|
+
activesupport
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activemodel (5.2.1)
|
11
|
+
activesupport (= 5.2.1)
|
12
|
+
activesupport (5.2.1)
|
13
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
|
+
i18n (>= 0.7, < 2)
|
15
|
+
minitest (~> 5.1)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
concurrent-ruby (1.0.5)
|
18
|
+
diff-lcs (1.3)
|
19
|
+
i18n (1.1.0)
|
20
|
+
concurrent-ruby (~> 1.0)
|
21
|
+
minitest (5.11.3)
|
22
|
+
rake (10.5.0)
|
23
|
+
rspec (3.8.0)
|
24
|
+
rspec-core (~> 3.8.0)
|
25
|
+
rspec-expectations (~> 3.8.0)
|
26
|
+
rspec-mocks (~> 3.8.0)
|
27
|
+
rspec-core (3.8.0)
|
28
|
+
rspec-support (~> 3.8.0)
|
29
|
+
rspec-expectations (3.8.1)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.8.0)
|
32
|
+
rspec-mocks (3.8.0)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.8.0)
|
35
|
+
rspec-support (3.8.0)
|
36
|
+
thread_safe (0.3.6)
|
37
|
+
tzinfo (1.2.5)
|
38
|
+
thread_safe (~> 0.1)
|
39
|
+
|
40
|
+
PLATFORMS
|
41
|
+
ruby
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
activemodel
|
45
|
+
activesupport
|
46
|
+
bundler (~> 1.12)
|
47
|
+
fluent-validation!
|
48
|
+
rake (~> 10.0)
|
49
|
+
rspec (~> 3.0)
|
50
|
+
|
51
|
+
BUNDLED WITH
|
52
|
+
1.12.5
|
data/README.md
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
# Fluent::Validation
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
Add this line to your application's Gemfile:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem 'fluent-validation'
|
9
|
+
```
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install fluent-validation
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Include `Fluent::Validation` to your models:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class User
|
25
|
+
include ActiveModel::Model
|
26
|
+
include Fluent::Validation
|
27
|
+
end
|
28
|
+
```
|
29
|
+
|
30
|
+
And add validations in groups for mandatory properties and optional properties:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
class User
|
34
|
+
include ActiveModel::Model
|
35
|
+
include Fluent::Validation
|
36
|
+
|
37
|
+
mandatories :first_name,
|
38
|
+
:last_name,
|
39
|
+
:username,
|
40
|
+
{ email: { format: { with: URI::MailTo::EMAIL_REGEXP }}},
|
41
|
+
{ contact_no: { numericality: true, format: { with: /\d+/ }}}
|
42
|
+
|
43
|
+
optionals gender: { inclusion: { in: ['M', 'F'] }}
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
47
|
+
The above would be the equivalent of:
|
48
|
+
|
49
|
+
```ruby
|
50
|
+
class User
|
51
|
+
include ActiveModel::Model
|
52
|
+
include Fluent::Validation
|
53
|
+
|
54
|
+
validates :first_name, presence: true
|
55
|
+
validates :last_name, presence: true
|
56
|
+
validates :username, presence: true
|
57
|
+
validates :email, presence: true, format: { with: URI::MailTo::EMAIL_REGEXP }
|
58
|
+
validates :contact_no, presence: true, numericality: true, format: { with: /\d+/ }
|
59
|
+
|
60
|
+
validates :gender, inclusion: { in: ['M', 'F'] }
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
## Development
|
65
|
+
|
66
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
67
|
+
|
68
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
69
|
+
|
70
|
+
## Contributing
|
71
|
+
|
72
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/fluent-validation.
|
73
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "fluent/validation"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'fluent/validation/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "fluent-validation"
|
8
|
+
spec.version = Fluent::Validation::VERSION
|
9
|
+
spec.authors = ["Rodette Pedro"]
|
10
|
+
spec.email = ["rodettecpedro@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = 'Declare Validations Fluently'
|
13
|
+
spec.description = 'Declare ActiveModel validations fluently'
|
14
|
+
spec.homepage = 'https://github.com/rcpedro/fluent-validation'
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
20
|
+
else
|
21
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
22
|
+
end
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
spec.bindir = "exe"
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ["lib"]
|
28
|
+
|
29
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
30
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
31
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
32
|
+
|
33
|
+
spec.add_dependency "activesupport"
|
34
|
+
spec.add_dependency "activemodel"
|
35
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
require 'fluent/validation/version'
|
3
|
+
|
4
|
+
module Fluent
|
5
|
+
module Validation
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
class_methods do
|
9
|
+
def attributes
|
10
|
+
@attributes ||= []
|
11
|
+
return @attributes
|
12
|
+
end
|
13
|
+
|
14
|
+
def mandatories(*fields)
|
15
|
+
fields.each do |field|
|
16
|
+
if field.is_a?(Hash)
|
17
|
+
self.mandatory(field.keys[0], field.values[0])
|
18
|
+
else
|
19
|
+
self.mandatory(field)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def optionals(*fields)
|
25
|
+
fields.each do |field|
|
26
|
+
if field.is_a?(Hash)
|
27
|
+
self.optional(field.keys[0], field.values[0])
|
28
|
+
else
|
29
|
+
self.optional(field)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def mandatory(field, options={})
|
35
|
+
self.attributes << field
|
36
|
+
self.validates(field, options.merge(presence: true))
|
37
|
+
end
|
38
|
+
|
39
|
+
def optional(field, options={})
|
40
|
+
self.attributes << field
|
41
|
+
self.validates(field, options)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fluent-validation
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rodette Pedro
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-09-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activemodel
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Declare ActiveModel validations fluently
|
84
|
+
email:
|
85
|
+
- rodettecpedro@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".rspec"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- Gemfile.lock
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- fluent-validation.gemspec
|
99
|
+
- lib/fluent/validation.rb
|
100
|
+
- lib/fluent/validation/version.rb
|
101
|
+
homepage: https://github.com/rcpedro/fluent-validation
|
102
|
+
licenses: []
|
103
|
+
metadata:
|
104
|
+
allowed_push_host: https://rubygems.org
|
105
|
+
post_install_message:
|
106
|
+
rdoc_options: []
|
107
|
+
require_paths:
|
108
|
+
- lib
|
109
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 2.4.5
|
122
|
+
signing_key:
|
123
|
+
specification_version: 4
|
124
|
+
summary: Declare Validations Fluently
|
125
|
+
test_files: []
|