universal_validators_rails 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 41c46d5361deed9b5b2bba5c5b5e07cb166a26ae
4
+ data.tar.gz: 58c35ed185f75bbc4b17a3686ee83909c8fa7a84
5
+ SHA512:
6
+ metadata.gz: 5ce2c226df5eecdd53325cdc3c8b95bae7e53ff62edc7ea20d54dd8f987bdcd31ced93f1b4942edc4a75d7b65bbb26a1e90de03f68bd5dc3102160258d5ef7e3
7
+ data.tar.gz: 08d94d3b66d9cbac1c93519011d291bda0696d3b1604ed56aa67d7baf2a865d6df32f63a61458826894c9237a602f99f7de39af6781d1df13d13d2ff3d968225
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in universal_validators_rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Damian Baćkowski
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,55 @@
1
+ # UniversalValidatorsRails [![Build Status](https://travis-ci.org/dbackowski/universal_validators_rails.svg?branch=master)](https://travis-ci.org/dbackowski/universal_validators_rails)
2
+
3
+ Rails validators for:
4
+
5
+ * date
6
+ * date_time
7
+ * ip address
8
+ * mac address
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'universal_validators_rails'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install universal_validators_rails
25
+
26
+ ## Usage
27
+
28
+ ```ruby
29
+ class User
30
+ include ActiveModel::Validations
31
+
32
+ attr_accessor :date, :date_time, :ip_address, :mac_address
33
+
34
+ validates :date, date: true
35
+ validates :date_time, date_time: true
36
+ validates :ip_address, ip_address: { with_mask: true }
37
+ validates :mac_address, mac_address: true
38
+ end
39
+
40
+ user = User.new
41
+ user.date = '2015-02-25'
42
+ user.date_time = '2015-02-25 12:33'
43
+ user.ip_address = '127.0.0.1/32'
44
+ user.mac_address = '00:0A:CD:00:CC:FE'
45
+ user.valid?
46
+ => true
47
+ ```
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it ( https://github.com/dbackowski/universal_validators_rails/fork )
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "universal_validators_rails"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ require 'universal_validators_rails/version'
2
+ require 'universal_validators'
3
+ require 'active_record'
4
+
5
+ class DateValidator < ActiveModel::EachValidator
6
+ def validate_each(record, attribute, value)
7
+ validator = ::UniversalValidators::DateValidator.new(value)
8
+ record.errors.add(attribute, @options[:message] || 'Invalid date format') unless validator.valid?
9
+ end
10
+ end
11
+
12
+ class DateTimeValidator < ActiveModel::EachValidator
13
+ def validate_each(record, attribute, value)
14
+ validator = ::UniversalValidators::DateTimeValidator.new(value)
15
+ record.errors.add(attribute, @options[:message] || 'Invalid date time format') unless validator.valid?
16
+ end
17
+ end
18
+
19
+ class IpAddressValidator < ActiveModel::EachValidator
20
+ def validate_each(record, attribute, value)
21
+ validator = ::UniversalValidators::IpValidator.new(value, @options[:with_mask] || false)
22
+ record.errors.add(attribute, @options[:message] || 'Invalid ip address format') unless validator.valid?
23
+ end
24
+ end
25
+
26
+ class MacAddressValidator < ActiveModel::EachValidator
27
+ def validate_each(record, attribute, value)
28
+ validator = ::UniversalValidators::MacAddressValidator.new(value)
29
+ record.errors.add(attribute, @options[:message] || 'Invalid mac address format') unless validator.valid?
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module UniversalValidatorsRails
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'universal_validators_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "universal_validators_rails"
8
+ spec.version = UniversalValidatorsRails::VERSION
9
+ spec.authors = ["Damian Baćkowski"]
10
+ spec.email = ["dbackowski@artcom.pl"]
11
+
12
+ spec.summary = %q{Rails validators for: date, date_time, ip address, mac address}
13
+ spec.description = %q{Rails validators for: date, date_time, ip address, mac address}
14
+ spec.homepage = "https://github.com/dbackowski/universal_validators_rails"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency 'universal_validators', '= 1.0.0', '= 1.0.0'
23
+ spec.add_runtime_dependency 'activerecord', '>= 4.0.1', '< 6.0'
24
+ spec.add_development_dependency "bundler", "~> 1.9"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.1"
27
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: universal_validators_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Damian Baćkowski
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: universal_validators
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: activerecord
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: 4.0.1
34
+ - - <
35
+ - !ruby/object:Gem::Version
36
+ version: '6.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 4.0.1
44
+ - - <
45
+ - !ruby/object:Gem::Version
46
+ version: '6.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.9'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ version: '1.9'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ~>
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ~>
80
+ - !ruby/object:Gem::Version
81
+ version: '3.1'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ~>
87
+ - !ruby/object:Gem::Version
88
+ version: '3.1'
89
+ description: 'Rails validators for: date, date_time, ip address, mac address'
90
+ email:
91
+ - dbackowski@artcom.pl
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - .gitignore
97
+ - .rspec
98
+ - .travis.yml
99
+ - Gemfile
100
+ - LICENSE.txt
101
+ - README.md
102
+ - Rakefile
103
+ - bin/console
104
+ - bin/setup
105
+ - lib/universal_validators_rails.rb
106
+ - lib/universal_validators_rails/version.rb
107
+ - universal_validators_rails.gemspec
108
+ homepage: https://github.com/dbackowski/universal_validators_rails
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.0.14
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: 'Rails validators for: date, date_time, ip address, mac address'
132
+ test_files: []