validated_object 2.3.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cbb448bc227821b65819e57ae210f715ea5295bf4c7f2e14925e560340a56a38
4
- data.tar.gz: 7e78815f3603aedfe4e4eda9cf5e626a64d0ef91f3f237b78a13e110697ce999
3
+ metadata.gz: 03a54694b8208e1e788cd55ece182bacdbfa75f3389db8c0dcc8902df92d9822
4
+ data.tar.gz: 03c58a85faa371f663201c0deb0e7ed8cb021f35aae8d3568e18f24e7db09c59
5
5
  SHA512:
6
- metadata.gz: 75745c4db0c873e4a4a5f63ca792a8646abcf5402408d0824e9a704e11112d91c5c303de4a4cf6addffd61ed9532f7327f602442c10ab4969b9332a6e3b6e161
7
- data.tar.gz: 4fa2b7800b2675469d85d5ce9a69f5bf2683fc56376f2bfa0fb623fd0491ad2d1c0833d44f55e124ebf067cc04066a5afd3f7d9ad6ea9d76d87ae00f917b770e
6
+ metadata.gz: 9f3bf8d6e81b2359e60f830d493e0a4fed9997bc21fa21c33f838794300e1b97514999ab42fb478a5cd22562ec89aa0dcfddf3a2c127b6b804f9f5f34faaea11
7
+ data.tar.gz: 5f05239f7150ffc10dc11544717298ec6500804ba4ab764cc8ba1dcb0bf1c6af7dfe59c927c829183902b575b2133ebc5278d2b1b9a3d8cd701dda8fd7a08f4d
@@ -0,0 +1,37 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ "master" ]
13
+ pull_request:
14
+ branches: [ "master" ]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ test:
21
+
22
+ runs-on: ubuntu-latest
23
+ strategy:
24
+ matrix:
25
+ ruby-version: ['3.1', '3.2', '3.3', '3.4']
26
+
27
+ steps:
28
+ - uses: actions/checkout@v3
29
+
30
+ - name: Set up Ruby
31
+ uses: ruby/setup-ruby@v1
32
+ with:
33
+ ruby-version: ${{ matrix.ruby-version }}
34
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
35
+
36
+ - name: Run tests
37
+ run: bundle exec rake
data/README.md CHANGED
@@ -1,21 +1,22 @@
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
-
1
+ [![Gem Version](https://badge.fury.io/rb/validated_object.svg)](https://badge.fury.io/rb/validated_object)
3
2
  # ValidatedObject
4
3
 
5
- Plain Old Ruby Objects + Rails Validations = **self-checking Ruby objects**.
6
- Here's a quick example of a common case: a class with an immutable,
7
- required, type-checked attribute:
4
+ `Plain Old Ruby` + `Rails Validations` = **self-checking Ruby objects**.
5
+
6
+ ## Example: A `Person` class that ensures its `name` isn't blank (nil or empty string):
8
7
 
9
8
  ```ruby
10
9
  class Person < ValidatedObject::Base
11
- validated_attr :name, type: String, presence: true
10
+ attr_reader :name
11
+ validates :name, presence: true
12
12
  end
13
13
 
14
- # Using it
15
- me = Person.new(name: 'Robb')
14
+ # Instantiating it runs the validations.
15
+ me = Person.new(name: 'Robb')
16
+ you = Person.new(name: '') # => ArgumentError: "Name can't be blank"
16
17
  ```
17
18
 
18
- I use classes like these as Data Transfer Objects at my system boundaries.
19
+ Note how Person's two lines of code are nothing new: `attr_reader` is standard Ruby. [`validates`](https://guides.rubyonrails.org/active_record_validations.html) is standard Rails. I use classes like these as Data Transfer Objects at my system boundaries.
19
20
 
20
21
 
21
22
  ## Goals
@@ -24,7 +25,7 @@ I use classes like these as Data Transfer Objects at my system boundaries.
24
25
  * Clean, minimal syntax
25
26
 
26
27
  This is a small layer around
27
- [ActiveModel::Validations](http://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-validates). (About 25 lines of code.) So if you know how to use Rails Validations, you're good to go. I wrote this to help with CSV data imports and [website microdata generation](https://github.com/dogweather/schema-dot-org).
28
+ [ActiveModel::Validations](http://api.rubyonrails.org/classes/ActiveModel/Validations/ClassMethods.html#method-i-validates). (About 25 lines of code.) So if you know how to use [Rails Validations](https://guides.rubyonrails.org/active_record_validations.html), you're good to go. I wrote this to help with CSV data imports and [website structured data](https://github.com/public-law/schema-dot-org).
28
29
 
29
30
 
30
31
  ## Usage
@@ -47,7 +48,7 @@ class Dog < ValidatedObject::Base
47
48
  end
48
49
  ```
49
50
 
50
- We can make it immutable with `attr_reader`:
51
+ Alternatively, we could make it immutable with Ruby's [attr_reader](https://bootrails.com/blog/ruby-attr-accessor-attr-writer-attr-reader/#2-attr_reader-attr_writer--attr_accessor):
51
52
 
52
53
  ```ruby
53
54
  class ImmutableDog < ValidatedObject::Base
@@ -58,10 +59,11 @@ class ImmutableDog < ValidatedObject::Base
58
59
  end
59
60
  ```
60
61
 
61
- > `attr_reader` followed by `validates` is such a common pattern that
62
- > there's a second DSL which wraps them up into one call: `validates_attr`.
62
+ And again, that `ImmutableDog` consists of one line of plain Ruby and two lines of standard Rails validations.
63
+
64
+ ### `attr_reader` followed by `validates` is such a common pattern that there's a DSL which wraps them up into one call: `validates_attr`.
63
65
 
64
- Here's the immutable version of `Dog` re-written with the simplified DSL:
66
+ Here's the immutable version of `Dog` re-written with the new, simplified DSL:
65
67
 
66
68
  ```ruby
67
69
  class ImmutableDog < ValidatedObject::Base
@@ -139,7 +141,7 @@ the data.
139
141
 
140
142
  ### Use in code generation
141
143
 
142
- My [Schema.org microdata generation gem](https://github.com/dogweather/schema-dot-org) uses ValidatedObjects to recursively create well formed HTML / JSON-LD.
144
+ My [Schema.org structured data gem](https://github.com/public-law/schema-dot-org) uses ValidatedObjects to recursively create well formed HTML / JSON-LD.
143
145
 
144
146
  ## Installation
145
147
 
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module ValidatedObject
5
- VERSION = '2.3.0'
5
+ VERSION = '2.3.1'
6
6
  end
@@ -5,6 +5,8 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'validated_object/version'
6
6
 
7
7
  Gem::Specification.new do |spec|
8
+ spec.required_ruby_version = '>= 3.1'
9
+
8
10
  spec.name = 'validated_object'
9
11
  spec.version = ValidatedObject::VERSION
10
12
  spec.authors = ['Robb Shecter']
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validated_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robb Shecter
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2023-10-12 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rake
@@ -87,6 +86,7 @@ executables: []
87
86
  extensions: []
88
87
  extra_rdoc_files: []
89
88
  files:
89
+ - ".github/workflows/ruby.yml"
90
90
  - ".gitignore"
91
91
  - ".rspec"
92
92
  - ".travis.yml"
@@ -125,7 +125,6 @@ licenses:
125
125
  - MIT
126
126
  metadata:
127
127
  allowed_push_host: https://rubygems.org
128
- post_install_message:
129
128
  rdoc_options: []
130
129
  require_paths:
131
130
  - lib
@@ -133,15 +132,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
133
132
  requirements:
134
133
  - - ">="
135
134
  - !ruby/object:Gem::Version
136
- version: '0'
135
+ version: '3.1'
137
136
  required_rubygems_version: !ruby/object:Gem::Requirement
138
137
  requirements:
139
138
  - - ">="
140
139
  - !ruby/object:Gem::Version
141
140
  version: '0'
142
141
  requirements: []
143
- rubygems_version: 3.4.20
144
- signing_key:
142
+ rubygems_version: 3.6.9
145
143
  specification_version: 4
146
144
  summary: Self-validating plain Ruby objects.
147
145
  test_files: []