activerecord-validations-helpers 0.1.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: e33166548c7be16ecda453102cddfb6a7543827b
4
+ data.tar.gz: 62a64782451e02d56a34f1b4a71b51e9f43402af
5
+ SHA512:
6
+ metadata.gz: 573173ffa8d7ae1358ed98859941d6c503dbffc3bdb0391a14d7983edbfaa59592bcc69e4f514a30868a4a0da9cc20b14889282fb35a837e7e1c2c545cdd87b9
7
+ data.tar.gz: f647b14810baaa42d091fcb6c62b8930fb4b633fe1f40a184c867a22e0d35b224c77a96679ecaafd2c9277254a3cda7827a99be30865f80067ca24cdcae7afda
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
@@ -0,0 +1,4 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.3
3
+ Exclude:
4
+ - 'activerecord-validations-helpers.gemspec'
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in activerecord-validations-helpers.gemspec
6
+ gemspec
@@ -0,0 +1,31 @@
1
+ # Activerecord::Validations::Helpers
2
+
3
+ Active Record validation helpers for your Rails project.
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem 'activerecord-validations-helpers'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install activerecord-validations-helpers
18
+
19
+ ## Usage
20
+
21
+ `assert_equal true, User.validation_options(:name, :presence)`
22
+
23
+ `assert_equal { less_than: 120, only_integer: true }, User.validation_options(:age, :numericality)`
24
+
25
+ `assert User.validates?(:name)`
26
+
27
+ `refute User.validates?(:age, :presence)`
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/raisintech/activerecord-validations-helpers.
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rake/testtask'
5
+ require 'rubocop/rake_task'
6
+ require 'yard'
7
+
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << 'test'
10
+ t.libs << 'lib'
11
+ t.test_files = FileList['test/**/*_test.rb']
12
+ end
13
+
14
+ RuboCop::RakeTask.new do |task|
15
+ task.fail_on_error = false
16
+ task.formatters = %w(simple)
17
+ end
18
+
19
+ YARD::Rake::YardocTask.new do |t|
20
+ t.files = ['lib/**/*.rb']
21
+ end
22
+
23
+ task default: %i(rubocop test yard)
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'activerecord/validations/helpers/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "activerecord-validations-helpers"
8
+ spec.version = Activerecord::Validations::Helpers::VERSION
9
+ spec.authors = ["Sergey Kuchmistov"]
10
+ spec.email = ["sergey.kuchmistov@gmail.com"]
11
+
12
+ spec.summary = %q{Extends activerecord validations with helpers}
13
+ spec.description = %q{Extends activerecord validations with helpers}
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
+ f.match(%r{^(test|spec|features)/})
17
+ end
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_dependency 'activerecord'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.13"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency 'simplecov'
27
+ spec.add_development_dependency 'sqlite3'
28
+ spec.add_development_dependency 'minitest'
29
+ spec.add_development_dependency 'simplecov-console'
30
+ spec.add_development_dependency 'minitest-reporters'
31
+ spec.add_development_dependency 'rubocop'
32
+ spec.add_development_dependency 'yard'
33
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'active_record'
6
+ require 'activerecord/validations/helpers'
7
+
8
+ ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
9
+
10
+ load 'test/schema.rb'
11
+ load 'test/models.rb'
12
+
13
+ require 'irb'
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle
7
+
8
+ rake
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'activerecord/validations/helpers/version'
4
+
5
+ module ActiveRecord
6
+ module Validations
7
+ # ActiveRecord helpers worked with validation reflections
8
+ module Helpers
9
+ def validates?(field, type = nil)
10
+ if type.nil?
11
+ validators_on(field).any?
12
+ else
13
+ validation_options(field, type)
14
+ end
15
+ end
16
+
17
+ def validation_options(field, type)
18
+ validation = validators_on(field).find { |v| v.kind == type }
19
+ if validation.present?
20
+ validation.options.present? ? validation.options : true
21
+ else
22
+ false
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ ActiveRecord::Base.extend ActiveRecord::Validations::Helpers
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Activerecord
4
+ module Validations
5
+ module Helpers
6
+ # Current version
7
+ VERSION = '0.1.0'
8
+ end
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: activerecord-validations-helpers
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Kuchmistov
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-06-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov-console
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: minitest-reporters
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rubocop
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: yard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Extends activerecord validations with helpers
154
+ email:
155
+ - sergey.kuchmistov@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rubocop.yml"
162
+ - Gemfile
163
+ - README.md
164
+ - Rakefile
165
+ - activerecord-validations-helpers.gemspec
166
+ - bin/console
167
+ - bin/setup
168
+ - lib/activerecord/validations/helpers.rb
169
+ - lib/activerecord/validations/helpers/version.rb
170
+ homepage:
171
+ licenses: []
172
+ metadata: {}
173
+ post_install_message:
174
+ rdoc_options: []
175
+ require_paths:
176
+ - lib
177
+ required_ruby_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ required_rubygems_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ requirements: []
188
+ rubyforge_project:
189
+ rubygems_version: 2.6.11
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: Extends activerecord validations with helpers
193
+ test_files: []