validated_object 2.0.2 → 2.0.3

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
  SHA256:
3
- metadata.gz: a9a4dc2f4ddb469aa576852bcaf36c911fdd948c7004587845addd89b942a1e2
4
- data.tar.gz: 553d9e9974c1e3b833f5a8501e5fea4ecea54d8bb9188403a316fbea3b13f49f
3
+ metadata.gz: 0c1aef88260ebc19d28fa8bd90a400ec6d05c45a60fea1632ebb1b81bbe2b456
4
+ data.tar.gz: 239216afd24adc90bb9ae4641253443a91d303e312f49b7bc6f348c541563f5f
5
5
  SHA512:
6
- metadata.gz: 7c0c33890be210b01c5b412795265c6c2babe78ab09f8f9743185b5134f659be85d42ff755428f73097cd0cd699fa8cb026311810fbf8ece289a7548e3e22081
7
- data.tar.gz: 36dd56f3e89c9911ffa7984f97ce3c0966f879e331f5b6141a3773948598e8eae712f0a6fbb5df9fadf9fc481176cb18a2f1537a93ba64f73cfd11070b3716dc
6
+ metadata.gz: 032c79475b1a99e990f4b04da2cda94cd5cca556cb38e385a783300ef675bfcd2ed51cc055d653b86f77b70270de87518cd7296b1c754a108f11c70d4e989c86
7
+ data.tar.gz: affdd5eb1d8dd2525c6b0fd7730fb907317ce0ad3bf8f105b42d67c66aba69e3389c65f7eae85dbfc67ed273e242761a34c67210153f4d9cbaaa694a3e6cac57
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- [![Gem Version](https://badge.fury.io/rb/validated_object.svg)](https://badge.fury.io/rb/validated_object) [![Build Status](https://travis-ci.org/dogweather/validated_object.svg?branch=master)](https://travis-ci.org/dogweather/validated_object) [![Code Climate](https://codeclimate.com/github/dogweather/validated_object/badges/gpa.svg)](https://codeclimate.com/github/dogweather/validated_object)
1
+ [![Gem Version](https://badge.fury.io/rb/validated_object.svg)](https://badge.fury.io/rb/validated_object) [![Build Status](https://travis-ci.org/public-law/validated_object.svg?branch=master)](https://travis-ci.org/public-law/validated_object) [![Code Climate](https://codeclimate.com/github/dogweather/validated_object/badges/gpa.svg)](https://codeclimate.com/github/dogweather/validated_object)
2
2
 
3
3
  # ValidatedObject
4
4
 
5
- Plain Old Ruby Objects + Rails Validations = self-checking Ruby objects.
5
+ Plain Old Ruby Objects + Rails Validations = **self-checking Ruby objects**.
6
6
 
7
7
 
8
8
  ## Goals
@@ -28,11 +28,13 @@ class Dog < ValidatedObject::Base
28
28
 
29
29
  # Plain old Rails
30
30
  validates :name, presence: true
31
+
32
+ # A new type-validation if you'd like to use it
31
33
  validates :birthday, type: Date, allow_nil: true # Strongly typed but optional
32
34
  end
33
35
  ```
34
36
 
35
- The `TypeValidator` is what enables `type: Date`, above. All classes can be checked, as well as a pseudo-class `Boolean`. E.g.:
37
+ The included `TypeValidator` is what enables `type: Date`, above. All classes can be checked, as well as a pseudo-class `Boolean`. E.g.:
36
38
 
37
39
  ```ruby
38
40
  #...
@@ -7,7 +7,7 @@ module ValidatedObject
7
7
  # @abstract Subclass and add `attr_accessor` and validations
8
8
  # to create custom validating objects.
9
9
  #
10
- # Uses [ActiveModel::Validations](http://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-validates)
10
+ # Uses {http://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-validates ActiveModel::Validations}
11
11
  # to create self-validating Plain Old Ruby objects. This is especially
12
12
  # useful when importing data from one system into another. This class also
13
13
  # creates very readable error messages.
@@ -44,7 +44,11 @@ module ValidatedObject
44
44
 
45
45
  EMPTY_HASH = {}.freeze
46
46
 
47
- # Implements a pseudo-boolean class.
47
+ # A private class definition, not intended to
48
+ # be used directly. Implements a pseudo-boolean class
49
+ # enabling validations like this:
50
+ #
51
+ # validates :enabled, type: Boolean
48
52
  class Boolean
49
53
  end
50
54
 
@@ -63,7 +67,9 @@ module ValidatedObject
63
67
  end
64
68
 
65
69
  # Run any validations and raise an error if invalid.
70
+ #
66
71
  # @raise [ArgumentError] if any validations fail.
72
+ # @return [ValidatedObject::Base] the receiver
67
73
  def check_validations!
68
74
  raise ArgumentError, errors.full_messages.join('; ') if invalid?
69
75
  self
@@ -73,6 +79,8 @@ module ValidatedObject
73
79
  # or a subclass. It supports a pseudo-boolean class for convenient
74
80
  # validation. (Ruby doesn't have a built-in Boolean.)
75
81
  #
82
+ # Automatically used in a `type` validation:
83
+ #
76
84
  # @example Ensure that weight is a number
77
85
  # class Dog < ValidatedObject::Base
78
86
  # attr_accessor :weight, :neutered
@@ -106,7 +114,7 @@ module ValidatedObject
106
114
  end
107
115
 
108
116
  def save_error(record, attribute, value, options)
109
- record.errors.add attribute,
117
+ record.errors.add attribute,
110
118
  options[:message] || "is a #{value.class}, not a #{options[:with]}"
111
119
  end
112
120
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ValidatedObject
4
- VERSION = '2.0.2'
4
+ VERSION = '2.0.3'
5
5
  end
@@ -1,5 +1,6 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'validated_object/version'
5
6
 
@@ -7,11 +8,11 @@ Gem::Specification.new do |spec|
7
8
  spec.name = 'validated_object'
8
9
  spec.version = ValidatedObject::VERSION
9
10
  spec.authors = ['Robb Shecter']
10
- spec.email = ['robb@weblaws.org']
11
+ spec.email = ['robb@public.law']
11
12
 
12
13
  spec.summary = 'Self-validating plain Ruby objects.'
13
14
  spec.description = 'A small wrapper around ActiveModel Validations.'
14
- spec.homepage = 'https://github.com/dogweather/validated_object'
15
+ spec.homepage = 'https://github.com/public-law/validated_object'
15
16
  spec.license = 'MIT'
16
17
 
17
18
  # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
@@ -27,8 +28,7 @@ Gem::Specification.new do |spec|
27
28
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
29
  spec.require_paths = ['lib']
29
30
 
30
- spec.add_development_dependency 'bundler', '~> 1.10'
31
- spec.add_development_dependency 'rake', '~> 10.0'
31
+ spec.add_development_dependency 'rake', '>= 12.3.3'
32
32
  spec.add_development_dependency 'rspec'
33
33
 
34
34
  spec.add_runtime_dependency 'activemodel', '>= 3.2.21'
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validated_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-04-05 00:00:00.000000000 Z
11
+ date: 2020-08-23 00:00:00.000000000 Z
12
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.10'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '1.10'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rake
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
- - - "~>"
17
+ - - ">="
32
18
  - !ruby/object:Gem::Version
33
- version: '10.0'
19
+ version: 12.3.3
34
20
  type: :development
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
- - - "~>"
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
- version: '10.0'
26
+ version: 12.3.3
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -68,7 +54,7 @@ dependencies:
68
54
  version: 3.2.21
69
55
  description: A small wrapper around ActiveModel Validations.
70
56
  email:
71
- - robb@weblaws.org
57
+ - robb@public.law
72
58
  executables: []
73
59
  extensions: []
74
60
  extra_rdoc_files: []
@@ -87,12 +73,12 @@ files:
87
73
  - lib/validated_object/version.rb
88
74
  - script/demo.rb
89
75
  - validated_object.gemspec
90
- homepage: https://github.com/dogweather/validated_object
76
+ homepage: https://github.com/public-law/validated_object
91
77
  licenses:
92
78
  - MIT
93
79
  metadata:
94
80
  allowed_push_host: https://rubygems.org
95
- post_install_message:
81
+ post_install_message:
96
82
  rdoc_options: []
97
83
  require_paths:
98
84
  - lib
@@ -107,9 +93,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
93
  - !ruby/object:Gem::Version
108
94
  version: '0'
109
95
  requirements: []
110
- rubyforge_project:
111
- rubygems_version: 2.7.5
112
- signing_key:
96
+ rubygems_version: 3.1.4
97
+ signing_key:
113
98
  specification_version: 4
114
99
  summary: Self-validating plain Ruby objects.
115
100
  test_files: []