failfast_validation 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '09187975ff8fd9e7d9b0180e0c20398bee117d45'
4
- data.tar.gz: a233b46dc16d7d76040d2539059db9e7b45d0891
3
+ metadata.gz: 2ed85f8452fb52c4df48bcdf17c9ed7e09f88300
4
+ data.tar.gz: 4f7782e2d03ff3b863f6b4b64224cf5d427ea509
5
5
  SHA512:
6
- metadata.gz: 5673489ac8583e8e254da555c2bf21cad32dcf21818977b579e1fc137ddb9ad1a518c336b021f24f44fad3786d35246f4963d532503231cb4e58d275a31db16e
7
- data.tar.gz: 6bae4958fff611e60f341bfe5d1c4add062e53924368c21c9312dc7534524273aafde36648bd8bad5679d78296ba3bbfd4f6027a9e75ea9a2988e88602eb0205
6
+ metadata.gz: 2abe74e37086d3a5613fe598f06967bffcfca8d643ab95069603c5e76c27e43c8e8bcfac1398594a0f51c05cfdf9b301d2e6d42047d2b1790280301bef2222bf
7
+ data.tar.gz: f197bca77343a82fb4eda2b13e06f6fe6bb6cd1dad1b34a822c271616e99045b727b0be6f8f0af73c6e593c919992b707b6c95b1ac4d54b29f5b0a3f8dd2bb9c
data/README.md CHANGED
@@ -1,11 +1,15 @@
1
1
  # FailfastValidation
2
- Failfast mode for ActiveModel::Validations
2
+ Failfast mode for ActiveModel::EachValidator
3
3
 
4
4
  ## Usage
5
5
  ```rb
6
6
  class YourModel
7
7
  include ActiveModel::Model
8
8
  include ActiveModel::FailfastValidation
9
+
10
+ failfast_validation :attr_name
11
+
12
+ # validates :attr_name, ....
9
13
  end
10
14
  ```
11
15
 
@@ -4,15 +4,34 @@ module ActiveModel
4
4
 
5
5
  module EachValidatorExtention
6
6
  def validate_each(record, attribute, value)
7
- if record.errors[attribute].empty?
7
+ if !(respond_to?(:_failfast_validation_attributes) && _failfast_validation_attributes.member?(attribute) && !record.errors[attribute].empty?)
8
8
  super(record, attribute, value)
9
9
  end
10
10
  end
11
11
  end
12
12
 
13
13
  included do
14
+ def self._failfast_validation_attributes
15
+ @_failfast_validation_attributes ||= []
16
+ end
17
+
18
+ def self.failfast_validation(*attrs)
19
+ @_failfast_validation_attributes = attrs
20
+ end
21
+
14
22
  def valid?(*args)
15
- self.class.validators.each { |validator| validator.extend(EachValidatorExtention) }
23
+ self.class.validators.each do |validator|
24
+ validator.define_singleton_method :_failfast_validation_attributes= do |attrs|
25
+ @_failfast_validation_attributes = attrs
26
+ end
27
+
28
+ validator.define_singleton_method :_failfast_validation_attributes do
29
+ @_failfast_validation_attributes
30
+ end
31
+
32
+ validator._failfast_validation_attributes = self.class._failfast_validation_attributes
33
+ validator.extend(EachValidatorExtention)
34
+ end
16
35
 
17
36
  super(*args)
18
37
  end
@@ -1,5 +1,4 @@
1
1
  require "failfast_validation/railtie"
2
- require 'active_model/failfast_validation'
3
2
 
4
3
  module FailfastValidation
5
4
  # Your code goes here...
@@ -1,4 +1,7 @@
1
1
  module FailfastValidation
2
2
  class Railtie < ::Rails::Railtie
3
+ initializer 'failfast_validation' do
4
+ require 'active_model/failfast_validation'
5
+ end
3
6
  end
4
7
  end
@@ -1,3 +1,3 @@
1
1
  module FailfastValidation
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: failfast_validation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shota Iguchi
@@ -102,5 +102,5 @@ rubyforge_project:
102
102
  rubygems_version: 2.6.14
103
103
  signing_key:
104
104
  specification_version: 4
105
- summary: Failfast mode for ActiveModel::Validations
105
+ summary: Failfast mode for ActiveModel::EachValidator
106
106
  test_files: []