active_warnings 0.1.3 → 0.1.4

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: 946c4ca069857e523b766ec1a59a17e6312241c4
4
- data.tar.gz: 89a230b5b5d9b99d95c4dbfc4880f682d4f34507
3
+ metadata.gz: 3ef4b6ee4ee25e15dd0b7ed506c8b6ac94bb5486
4
+ data.tar.gz: d43cf2e0ea7c0fa868a882818015aab03d0fd9fc
5
5
  SHA512:
6
- metadata.gz: 181e4c32e350b14a5e72c3d7df8e8422346d4f95b2b05e1b6ccd7921a2b0314f80467c5d641a902d0366516cea68058fd8a26ae3411ac717c9eb364030473112
7
- data.tar.gz: 200be1d6c1ad4245b1e1b1c4b36c14e39a3ac52018c5d2f5c6f49bc7cd05353fe1a1835cd8ef5ac918899bf956e0a411e669fd54b2ca39f01613e51872af0269
6
+ metadata.gz: 38c4ed1ef15f88ea32346533529a93b34ffb7cf848f6d8e44268e3f47d66e07a618390221fb18e36ae3af877bf49b767f115ee156b9ed7f181e68115c705a043
7
+ data.tar.gz: e472e787b804bd2b9932ec0b06e59c513101c34daa0a975bc832f4263adc03b84875168391f4b344bc03a44ba4b4f2dd15e792a2ddfc339ebba61be2a7d98136
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # ActiveWarnings [![Build Status](https://travis-ci.org/s12chung/active_warnings.svg?branch=test_active_model)](https://travis-ci.org/s12chung/active_warnings)
2
2
 
3
- `ActiveModel::Validations` separate for warnings.
3
+ Separate `ActiveModel::Validations` errors for warnings.
4
4
 
5
5
  ## Installation
6
6
 
@@ -27,12 +27,11 @@ class BasicModel
27
27
  attr_accessor :name
28
28
  def initialize(name); @name = name; end
29
29
 
30
- validates :name, presence: true
31
-
32
30
  warnings do
33
- # to share the same validators, error related methods now correspond to warnings. ie:
34
- # the method #valid? == #safe? and #errors == #warnings
35
31
  validates :name, absence: true
32
+
33
+ # Example custom validation
34
+ validate { errors.add(:name, "is some_name") if name == "some_name" }
36
35
  end
37
36
  end
38
37
 
@@ -40,14 +39,19 @@ end
40
39
  # Basic Use
41
40
  #
42
41
  model = BasicModel.new("some_name")
43
- model.valid? # => true
44
- model.errors.keys # => []
45
42
 
43
+ # Regular ActiveModel::Validations errors work separately
44
+ model.valid? # => true
45
+ model.errors.full_messages # => []
46
+
47
+ # like `#valid?`
46
48
  model.safe? # => false
47
49
  model.no_warnings? # => false, equivalent to #safe?
50
+ # like `#invalid?`
48
51
  model.unsafe? # => true
49
52
  model.has_warnings? # => true, equivalent to #unsafe?
50
- model.warnings.keys # => [:name]
53
+ # like `#errors`
54
+ model.warnings.full_messages # => ["Name must be blank", "Name is some_name"]
51
55
 
52
56
  #
53
57
  # Advanced Use
@@ -7,10 +7,9 @@ require 'active_warnings/validator'
7
7
 
8
8
  module ActiveWarnings
9
9
  extend ActiveSupport::Concern
10
+ include ActiveModel::Validations
10
11
 
11
12
  included do
12
- include ActiveModel::Validations
13
-
14
13
  define_callbacks :validate_warning, scope: :name
15
14
 
16
15
  def errors
@@ -1,3 +1,3 @@
1
1
  module ActiveWarnings
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_warnings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Chung
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-21 00:00:00.000000000 Z
11
+ date: 2016-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
64
  version: '0'
65
65
  requirements: []
66
66
  rubyforge_project:
67
- rubygems_version: 2.4.5.1
67
+ rubygems_version: 2.5.1
68
68
  signing_key:
69
69
  specification_version: 4
70
70
  summary: Separate ActiveModel::Validations for warnings.