contracted_value 0.1.0 → 0.1.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: fec55efa08a60e3b4f73c1b8813af1a6a188493c6a870a08083d008dbff19a18
4
- data.tar.gz: 70a611199db2edce337a2571b3a5ef22be515081c671ef64aff389658e6d3c39
3
+ metadata.gz: 761fdc9b4b487bb54d59724fa87a6e2e3ca1665cae0774bc2f7cdcf50d076913
4
+ data.tar.gz: c051835f898ce826968eb7616fc414ffeff3677926b48d001904528432354a88
5
5
  SHA512:
6
- metadata.gz: b709ba4fd278372200a7b97379ba6fb69eb73099e9c13c0006537c6de921aa5228242b5d742f6c46c4969da89789b2edd40672a184fe5074d62101db5e3e09ac
7
- data.tar.gz: efdd16b4cc5343a984105a3ac19e98caab7f88b5e399793cd99f94753f57711f4cf821d3ff9daeee864158248e3a47b7beeec3da058cfc3c3839d9973fc888ae
6
+ metadata.gz: a6d714074711c3d1ef3856e15cf2ba4e0035f90c493cdebe485d90aef52990f8b03d0055c0a96d7f34ccbbc1b230e0f905ea7baf8258200e739ec0bdd0b3cb87
7
+ data.tar.gz: 7543ae38d5eddb8b0304a7171caec91b4472b66210752c79783b481ee07b32b34924d122db46cf90442ed6127fe4055d862224b3c49b1f0c33b1d07fb53753cc
@@ -0,0 +1,13 @@
1
+ # Lines starting with '#' are comments.
2
+ # Each line is a file pattern followed by one or more owners.
3
+
4
+ # These owners will be the default owners for everything in the repo.
5
+ * @PikachuEXE
6
+
7
+ # Order is important. The last matching pattern has the most precedence.
8
+ # So if a pull request only touches javascript files, only these owners
9
+ # will be requested to review.
10
+ # *.rb @PikachuEXE
11
+
12
+ # You can also use email addresses if you prefer.
13
+ # docs/* docs@example.com
@@ -0,0 +1,2 @@
1
+ github:
2
+ - PikachuEXE
@@ -0,0 +1,20 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: monthly
7
+ time: "06:00"
8
+ timezone: Asia/Hong_Kong
9
+ open-pull-requests-limit: 10
10
+ labels:
11
+ - "dependencies"
12
+ - package-ecosystem: github-actions
13
+ directory: "/"
14
+ schedule:
15
+ interval: monthly
16
+ time: "06:00"
17
+ timezone: Asia/Hong_Kong
18
+ open-pull-requests-limit: 10
19
+ labels:
20
+ - "dependencies"
@@ -0,0 +1,63 @@
1
+ name: Coverage
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - master
7
+ paths-ignore:
8
+ - 'README.md'
9
+ push:
10
+ branches:
11
+ - master
12
+ paths-ignore:
13
+ - 'README.md'
14
+
15
+ jobs:
16
+ coverage:
17
+ name: Coverage
18
+ # Homemade support for [ci skip] no longer needed
19
+ # https://github.blog/changelog/2021-02-08-github-actions-skip-pull-request-and-push-workflows-with-skip-ci/
20
+ # if: "contains(github.event.commits[0].message, '[ci skip]') == false"
21
+ strategy:
22
+ fail-fast: false
23
+ matrix:
24
+ os:
25
+ - ubuntu-latest
26
+ ruby:
27
+ - "2.7"
28
+ gemfile:
29
+ - gemfiles/contracts_16_0.gemfile
30
+ env:
31
+ BUNDLE_GEMFILE: ${{ matrix.gemfile }}
32
+ COVERALLS: true
33
+ runs-on: ${{ matrix.os }}
34
+ steps:
35
+ - name: Checkout
36
+ uses: actions/checkout@v3
37
+
38
+ - name: Setup Ruby
39
+ uses: ruby/setup-ruby@v1
40
+ with:
41
+ ruby-version: ${{ matrix.ruby }}
42
+ bundler-cache: true
43
+
44
+ - name: Collect coverage info
45
+ run: bundle exec rake spec
46
+
47
+ - name: Coveralls Parallel
48
+ uses: coverallsapp/github-action@master
49
+ continue-on-error: true
50
+ with:
51
+ github-token: ${{ secrets.github_token }}
52
+ flag-name: run-${{ matrix.ruby }}-${{ matrix.gemfile }}
53
+ parallel: true
54
+
55
+ finish:
56
+ needs: coverage
57
+ runs-on: ubuntu-latest
58
+ steps:
59
+ - name: Send to Coveralls
60
+ uses: coverallsapp/github-action@master
61
+ with:
62
+ github-token: ${{ secrets.GITHUB_TOKEN }}
63
+ parallel-finished: true
@@ -0,0 +1,56 @@
1
+ name: Tests
2
+
3
+ on:
4
+ pull_request:
5
+ branches:
6
+ - master
7
+ paths-ignore:
8
+ - 'README.md'
9
+ push:
10
+ branches:
11
+ - master
12
+ paths-ignore:
13
+ - 'README.md'
14
+
15
+ jobs:
16
+ unit_tests:
17
+ name: Unit Tests
18
+ # Homemade support for [ci skip] no longer needed
19
+ # https://github.blog/changelog/2021-02-08-github-actions-skip-pull-request-and-push-workflows-with-skip-ci/
20
+ # if: "contains(github.event.commits[0].message, '[ci skip]') == false"
21
+ strategy:
22
+ fail-fast: false
23
+ matrix:
24
+ os:
25
+ - ubuntu-latest
26
+ ruby:
27
+ - "3.0"
28
+ - "3.1"
29
+ gemfile:
30
+ - gemfiles/contracts_17_0.gemfile
31
+ allow_failures:
32
+ - false
33
+ include:
34
+ - os: ubuntu-latest
35
+ ruby: "2.7"
36
+ gemfile: gemfiles/contracts_16_0.gemfile
37
+ allow_failures: false
38
+ - os: ubuntu-latest
39
+ ruby: "ruby-head"
40
+ gemfile: gemfiles/contracts_17_0.gemfile
41
+ allow_failures: true
42
+ env:
43
+ BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
44
+ ALLOW_FAILURES: "${{ matrix.allow_failures }}"
45
+ runs-on: ${{ matrix.os }}
46
+ continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' }}
47
+ steps:
48
+ - name: Checkout
49
+ uses: actions/checkout@v3
50
+ - name: Setup Ruby
51
+ uses: ruby/setup-ruby@v1
52
+ with:
53
+ ruby-version: ${{ matrix.ruby }}
54
+ bundler-cache: true
55
+ - name: Test
56
+ run: bundle exec rake spec || $ALLOW_FAILURES
data/Appraisals CHANGED
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- appraise "contracts_15_0" do
4
- gem "contracts", "~> 0.15.0"
5
- end
6
-
7
3
  appraise "contracts_16_0" do
8
4
  gem "contracts", "~> 0.16.0"
9
5
  end
data/CHANGELOG.md CHANGED
@@ -18,6 +18,17 @@ This project adheres to [Semantic Versioning](http://semver.org/).
18
18
  - Nothing
19
19
 
20
20
 
21
+ ## [Unreleased]
22
+
23
+ ### Changed
24
+
25
+ - Requires Ruby 2.7 (due to use of ["Forward all arguments" syntax](https://rubyreferences.github.io/rubychanges/2.7.html#keyword-argument-related-changes))
26
+
27
+ ### Fixed
28
+
29
+ - Fix Ruby 3.x compatibility
30
+
31
+
21
32
  ## 0.1.0 - 2019-06-05
22
33
 
23
34
  ### Added
data/README.md CHANGED
@@ -2,15 +2,6 @@
2
2
 
3
3
  Library for creating contracted immutable(by default) value objects
4
4
 
5
- [![Gem Version](http://img.shields.io/gem/v/contracted_value.svg?style=flat-square)](http://badge.fury.io/rb/contracted_value)
6
- [![License](https://img.shields.io/github/license/PikachuEXE/contracted_value.svg?style=flat-square)](http://badge.fury.io/rb/contracted_value)
7
-
8
- [![Build Status](http://img.shields.io/travis/PikachuEXE/contracted_value.svg?style=flat-square)](https://travis-ci.org/PikachuEXE/contracted_value)
9
-
10
- [![Code Climate](https://img.shields.io/codeclimate/maintainability/PikachuEXE/contracted_value.svg?style=flat-square)](https://codeclimate.com/github/PikachuEXE/contracted_value)
11
- [![Coverage Status](https://img.shields.io/codecov/c/github/PikachuEXE/contracted_value.svg?style=flat-square)](https://codecov.io/gh/PikachuEXE/contracted_value)
12
-
13
-
14
5
  This gem allows creation of value objects which are
15
6
  - contracted (enforced by [`contracts.ruby`](https://github.com/egonSchiele/contracts.ruby))
16
7
  - immutable (enforced by [`ice_nine`](https://github.com/dkubb/ice_nine))
@@ -18,6 +9,19 @@ This gem allows creation of value objects which are
18
9
  See details explanation in below sections
19
10
 
20
11
 
12
+ ## Status
13
+
14
+ [![GitHub Build Status](https://img.shields.io/github/workflow/status/PikachuEXE/contracted_value/Tests?style=flat-square)](https://github.com/PikachuEXE/contracted_value/actions?query=workflow%3ATests)
15
+
16
+ [![Gem Version](http://img.shields.io/gem/v/contracted_value.svg?style=flat-square)](http://badge.fury.io/rb/contracted_value)
17
+ [![License](https://img.shields.io/github/license/PikachuEXE/contracted_value.svg?style=flat-square)](http://badge.fury.io/rb/contracted_value)
18
+
19
+ [![Code Climate](https://img.shields.io/codeclimate/maintainability/PikachuEXE/contracted_value.svg?style=flat-square)](https://codeclimate.com/github/PikachuEXE/contracted_value)
20
+ [![Coverage Status](http://img.shields.io/coveralls/PikachuEXE/contracted_value.svg?style=flat-square)](https://coveralls.io/r/PikachuEXE/contracted_value)
21
+
22
+ > The above badges are generated by https://shields.io/
23
+
24
+
21
25
  ## Installation
22
26
 
23
27
  Add this line to your application's Gemfile:
@@ -146,6 +150,36 @@ location_range = ::Geometry::LocationRange::Entry.new(location)
146
150
 
147
151
  ```
148
152
 
153
+ #### Passing objects of different `ContractedValue::Value` subclasses to `.new`
154
+ Possible due to the implementation calling `#to_h` for `ContractedValue::Value` objects
155
+ But in case the attribute names are different, or adding new attributes/updating existing attributes is needed
156
+ You will need to call `#to_h` to get a `Hash` and do whatever modification needed before passing into `.new`
157
+
158
+ ```ruby
159
+ class Pokemon < ::ContractedValue::Value
160
+ attribute(:name)
161
+ attribute(:type)
162
+ end
163
+
164
+ class Pikachu < ::Pokemon
165
+ attribute(:name, default_value: "Pikachu")
166
+ attribute(:type, default_value: "Thunder")
167
+ end
168
+
169
+ # Ya I love using pokemon as examples, problem?
170
+ pikachu = Pikachu.new(name: "PikaPika")
171
+ pikachu.name #=> "PikaPika"
172
+ pikachu.type #=> "Thunder"
173
+
174
+ pokemon1 = Pokemon.new(pikachu)
175
+ pokemon1.name #=> "PikaPika"
176
+ pokemon1.type #=> "Thunder"
177
+
178
+ pokemon2 = Pokemon.new(pikachu.to_h.merge(name: "Piak"))
179
+ pokemon2.name #=> "Piak"
180
+ pokemon2.type #=> "Thunder"
181
+ ```
182
+
149
183
 
150
184
  ### Input Validation
151
185
 
@@ -154,9 +188,9 @@ Input values are validated on object creation (instead of on attribute value acc
154
188
  - Value presence
155
189
 
156
190
  #### Value contract
157
- An attribute can be declared without any contract, and any input value would be pass the validation
158
- But you can pass a contract via `contract` option (must be a [`contracts.ruby`](https://github.com/egonSchiele/contracts.ruby) contract)
159
- Passing input value violating an attribute's contract would cause an error
191
+ An attribute can be declared without any contract, and any input value would be pass the validation
192
+ But you can pass a contract via `contract` option (must be a [`contracts.ruby`](https://github.com/egonSchiele/contracts.ruby) contract)
193
+ Passing input value violating an attribute's contract would cause an error
160
194
 
161
195
  ```ruby
162
196
  class YetAnotherRationalNumber < ::ContractedValue::Value
@@ -181,10 +215,10 @@ YetAnotherRationalNumber.new(
181
215
  ```
182
216
 
183
217
  #### Value presence
184
- An attribute declared should be provided a value on object creation, even the input value is `nil`
185
- Otherwise an error is raised
186
- You can pass default value via option `default_value`
187
- The default value will need to confront to the contract passed in `contract` option too
218
+ An attribute declared should be provided a value on object creation, even the input value is `nil`
219
+ Otherwise an error is raised
220
+ You can pass default value via option `default_value`
221
+ The default value will need to confront to the contract passed in `contract` option too
188
222
 
189
223
 
190
224
  ```ruby
@@ -289,6 +323,8 @@ end
289
323
 
290
324
  # Ya I love using pokemon as examples, problem?
291
325
  pikachu = Pikachu.new(name: "PikaPika")
326
+ pikachu.name #=> "PikaPika"
327
+ pikachu.type #=> "Thunder"
292
328
  ```
293
329
 
294
330
  #### All existing attributes can be redeclared
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
32
32
  s.add_dependency "ice_nine"
33
33
 
34
34
  s.add_development_dependency "bundler", ">= 1.0.0"
35
- s.add_development_dependency "rake", ">= 10.0", "<= 13.0"
35
+ s.add_development_dependency "rake", ">= 10.0", "<= 14.0"
36
36
  s.add_development_dependency "pry"
37
37
 
38
38
  s.add_development_dependency "appraisal", "~> 2.0"
@@ -40,8 +40,8 @@ Gem::Specification.new do |s|
40
40
  s.add_development_dependency "rspec", "~> 3.0"
41
41
  s.add_development_dependency "rspec-its", "~> 1.0"
42
42
 
43
- s.add_development_dependency "simplecov"
44
- s.add_development_dependency "codecov"
43
+ s.add_development_dependency "simplecov", ">= 0.21"
44
+ s.add_development_dependency "simplecov-lcov", ">= 0.8"
45
45
 
46
46
  s.add_development_dependency "gem-release", ">= 0.7"
47
47
 
@@ -49,7 +49,7 @@ Gem::Specification.new do |s|
49
49
 
50
50
  s.add_development_dependency "rubocop", ">= 0.70"
51
51
 
52
- s.required_ruby_version = ">= 2.3.0"
52
+ s.required_ruby_version = ">= 2.7.0"
53
53
 
54
54
  s.required_rubygems_version = ">= 1.4.0"
55
55
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "contracts", "~> 0.15.0"
5
+ gem "contracts", "~> 0.17.0"
6
6
 
7
7
  gemspec path: "../"
@@ -131,7 +131,7 @@ module ContractedValue
131
131
  end
132
132
 
133
133
  class Attribute
134
- def self.new(*)
134
+ def self.new(...)
135
135
  ::IceNine.deep_freeze(super)
136
136
  end
137
137
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContractedValue
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/spec/spec_helper.rb CHANGED
@@ -1,15 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
4
- require "contracted_value"
5
-
6
- if ENV["TRAVIS"]
3
+ if ENV["COVERALLS"]
7
4
  require "simplecov"
8
- SimpleCov.start
5
+ require "simplecov-lcov"
6
+
7
+ SimpleCov::Formatter::LcovFormatter.config do |c|
8
+ c.report_with_single_file = true
9
+ c.single_report_path = "coverage/lcov.info"
10
+ end
9
11
 
10
- require "codecov"
11
- SimpleCov.formatter = SimpleCov::Formatter::Codecov
12
+ SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new(
13
+ [SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::LcovFormatter]
14
+ )
15
+
16
+ SimpleCov.start do
17
+ add_filter "spec/"
18
+ end
12
19
  end
13
20
 
21
+ $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
22
+ require "contracted_value"
23
+
14
24
  require "rspec"
15
25
  require "rspec/its"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contracted_value
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - PikachuEXE
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-05 00:00:00.000000000 Z
11
+ date: 2022-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: contracts
@@ -61,7 +61,7 @@ dependencies:
61
61
  version: '10.0'
62
62
  - - "<="
63
63
  - !ruby/object:Gem::Version
64
- version: '13.0'
64
+ version: '14.0'
65
65
  type: :development
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
@@ -71,7 +71,7 @@ dependencies:
71
71
  version: '10.0'
72
72
  - - "<="
73
73
  - !ruby/object:Gem::Version
74
- version: '13.0'
74
+ version: '14.0'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: pry
77
77
  requirement: !ruby/object:Gem::Requirement
@@ -134,28 +134,28 @@ dependencies:
134
134
  requirements:
135
135
  - - ">="
136
136
  - !ruby/object:Gem::Version
137
- version: '0'
137
+ version: '0.21'
138
138
  type: :development
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
142
  - - ">="
143
143
  - !ruby/object:Gem::Version
144
- version: '0'
144
+ version: '0.21'
145
145
  - !ruby/object:Gem::Dependency
146
- name: codecov
146
+ name: simplecov-lcov
147
147
  requirement: !ruby/object:Gem::Requirement
148
148
  requirements:
149
149
  - - ">="
150
150
  - !ruby/object:Gem::Version
151
- version: '0'
151
+ version: '0.8'
152
152
  type: :development
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - ">="
157
157
  - !ruby/object:Gem::Version
158
- version: '0'
158
+ version: '0.8'
159
159
  - !ruby/object:Gem::Dependency
160
160
  name: gem-release
161
161
  requirement: !ruby/object:Gem::Requirement
@@ -208,9 +208,13 @@ extra_rdoc_files: []
208
208
  files:
209
209
  - ".codeclimate.yml"
210
210
  - ".editorconfig"
211
+ - ".github/CODEOWNERS"
212
+ - ".github/FUNDING.yml"
213
+ - ".github/dependabot.yml"
214
+ - ".github/workflows/coverage.yml"
215
+ - ".github/workflows/tests.yaml"
211
216
  - ".gitignore"
212
217
  - ".rubocop.yml"
213
- - ".travis.yml"
214
218
  - Appraisals
215
219
  - CHANGELOG.md
216
220
  - Gemfile
@@ -218,8 +222,8 @@ files:
218
222
  - README.md
219
223
  - Rakefile
220
224
  - contracted_value.gemspec
221
- - gemfiles/contracts_15_0.gemfile
222
225
  - gemfiles/contracts_16_0.gemfile
226
+ - gemfiles/contracts_17_0.gemfile
223
227
  - lib/contracted_value.rb
224
228
  - lib/contracted_value/core.rb
225
229
  - lib/contracted_value/version.rb
@@ -230,7 +234,7 @@ homepage: http://github.com/PikachuEXE/contracted_value
230
234
  licenses:
231
235
  - MIT
232
236
  metadata: {}
233
- post_install_message:
237
+ post_install_message:
234
238
  rdoc_options: []
235
239
  require_paths:
236
240
  - lib
@@ -238,15 +242,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
238
242
  requirements:
239
243
  - - ">="
240
244
  - !ruby/object:Gem::Version
241
- version: 2.3.0
245
+ version: 2.7.0
242
246
  required_rubygems_version: !ruby/object:Gem::Requirement
243
247
  requirements:
244
248
  - - ">="
245
249
  - !ruby/object:Gem::Version
246
250
  version: 1.4.0
247
251
  requirements: []
248
- rubygems_version: 3.0.3
249
- signing_key:
252
+ rubygems_version: 3.3.21
253
+ signing_key:
250
254
  specification_version: 4
251
255
  summary: Some Tweaks for ActiveRecord
252
256
  test_files:
data/.travis.yml DELETED
@@ -1,25 +0,0 @@
1
- # Send builds to container-based infrastructure
2
- # http://docs.travis-ci.com/user/workers/container-based-infrastructure/
3
- sudo: false
4
- language: ruby
5
- before_install:
6
- # This is required since 2.6.8 has issue when installing `rainbow`
7
- # https://github.com/sickill/rainbow/issues/48
8
- - gem update --system
9
- - gem --version
10
- cache:
11
- - bundler
12
- rvm:
13
- - 2.4
14
- - 2.5
15
- - 2.6
16
- - 2.7
17
- - ruby-head
18
- gemfile:
19
- - gemfiles/contracts_15_0.gemfile
20
- - gemfiles/contracts_16_0.gemfile
21
- matrix:
22
- fast_finish: true
23
- allow_failures:
24
- - rvm: 2.7
25
- - rvm: ruby-head