u-attributes 2.7.0 → 2.8.0
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 +4 -4
- data/.github/workflows/ci.yml +27 -0
- data/.vscode/settings.json +8 -0
- data/Gemfile +2 -2
- data/README.md +4 -4
- data/bin/prepare_coverage +27 -0
- data/bin/test +48 -0
- data/lib/micro/attributes/features/accept.rb +2 -2
- data/lib/micro/attributes/macros.rb +11 -1
- data/lib/micro/attributes/version.rb +1 -1
- data/lib/micro/attributes.rb +9 -5
- metadata +10 -9
- data/.travis.sh +0 -45
- data/.travis.yml +0 -33
- data/test.sh +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75a44be0f1b71d41abdfd3e9c81f67527760a4a8f0202818fd7f04782680922b
|
4
|
+
data.tar.gz: bbb26faf04daffd2e92b18eb4e363d85c7677ed5ed3fb09bda485d8b34c8296d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e7da00d4786086edc9607533ef9c9632b10dd2200ddee29a46551d311c8e5ee8c5549d161f8ea6881c95c529abbdd4a2c48fd28635464606a7877b0d94a6488
|
7
|
+
data.tar.gz: aa42ef9c78b7f60514ef062b78d1b6f4eb3589ce1d39ab13d6459d2a164e3dcfa8b4f54660598df76afe4b42b8087cf9060f57398609f59508952bfd49c0cda1
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
name: build
|
3
|
+
on: [push]
|
4
|
+
jobs:
|
5
|
+
test:
|
6
|
+
runs-on: ubuntu-latest
|
7
|
+
strategy:
|
8
|
+
matrix:
|
9
|
+
ruby: [2.2, 2.3, 2.4, 2.5, 2.6, 3.0]
|
10
|
+
steps:
|
11
|
+
- uses: actions/checkout@v2
|
12
|
+
- uses: ruby/setup-ruby@v1
|
13
|
+
with:
|
14
|
+
ruby-version: ${{ matrix.ruby }}
|
15
|
+
bundler-cache: true
|
16
|
+
- name: Test and generate coverage
|
17
|
+
run: bin/test
|
18
|
+
- name: Format coverage
|
19
|
+
if: ${{ matrix.ruby >= 3 }}
|
20
|
+
run: bin/prepare_coverage
|
21
|
+
- uses: paambaati/codeclimate-action@v2.7.5
|
22
|
+
if: ${{ matrix.ruby >= 3 }}
|
23
|
+
env:
|
24
|
+
CC_TEST_REPORTER_ID: 9015766fe58e0abd5ab58050ddfc67708e0b11430b3d3999ac17139ffcb4d3e7
|
25
|
+
with:
|
26
|
+
debug: true
|
27
|
+
coverageLocations: coverage/.resultset.json:simplecov
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'u-case', '~> 4.
|
3
|
+
gem 'u-case', '~> 4.5', '>= 4.5.1'
|
4
4
|
|
5
5
|
activemodel_version = ENV['ACTIVEMODEL_VERSION']
|
6
6
|
|
@@ -20,7 +20,7 @@ simplecov_version =
|
|
20
20
|
case RUBY_VERSION
|
21
21
|
when /\A2.[23]/ then '0.17.1'
|
22
22
|
when /\A2.4/ then '~> 0.18.5'
|
23
|
-
else '~> 0.
|
23
|
+
else '~> 0.21.2'
|
24
24
|
end
|
25
25
|
|
26
26
|
group :test do
|
data/README.md
CHANGED
@@ -12,8 +12,8 @@
|
|
12
12
|
<img alt="Gem" src="https://img.shields.io/gem/v/u-attributes.svg?style=flat-square">
|
13
13
|
</a>
|
14
14
|
|
15
|
-
<a href="https://
|
16
|
-
<img alt="Build Status" src="https://
|
15
|
+
<a href="https://github.com/serradura/u-attributes/actions/workflows/ci.yml">
|
16
|
+
<img alt="Build Status" src="https://github.com/serradura/u-attributes/actions/workflows/ci.yml/badge.svg">
|
17
17
|
</a>
|
18
18
|
|
19
19
|
<a href="https://codeclimate.com/github/serradura/u-attributes/maintainability">
|
@@ -33,7 +33,7 @@ So, if you change [[1](#with_attribute)] [[2](#with_attributes)] an attribute of
|
|
33
33
|
Version | Documentation
|
34
34
|
---------- | -------------
|
35
35
|
unreleased | https://github.com/serradura/u-case/blob/main/README.md
|
36
|
-
2.
|
36
|
+
2.8.0 | https://github.com/serradura/u-case/blob/v2.x/README.md
|
37
37
|
1.2.0 | https://github.com/serradura/u-case/blob/v1.x/README.md
|
38
38
|
|
39
39
|
# Table of contents <!-- omit in toc -->
|
@@ -94,7 +94,7 @@ gem 'u-attributes'
|
|
94
94
|
| u-attributes | branch | ruby | activemodel |
|
95
95
|
| -------------- | ------- | -------- | ------------- |
|
96
96
|
| unreleased | main | >= 2.2.0 | >= 3.2, < 7 |
|
97
|
-
| 2.
|
97
|
+
| 2.8.0 | v2.x | >= 2.2.0 | >= 3.2, < 7 |
|
98
98
|
| 1.2.0 | v1.x | >= 2.2.0 | >= 3.2, < 6.1 |
|
99
99
|
|
100
100
|
> **Note**: The activemodel is an optional dependency, this module [can be enabled](#activemodelvalidation-extension) to validate the attributes.
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
# Borrowed from https://gist.github.com/qortex/7e7c49f3731391a91ee898336183acef
|
4
|
+
|
5
|
+
# Temporary hack to get CodeClimate to work with SimpleCov 0.18 JSON format until issue is fixed
|
6
|
+
# upstream: https://github.com/codeclimate/test-reporter/issues/413
|
7
|
+
|
8
|
+
require "json"
|
9
|
+
|
10
|
+
filename = "coverage/.resultset.json"
|
11
|
+
contents = JSON.parse(File.read(filename))
|
12
|
+
|
13
|
+
def remove_lines_key(obj)
|
14
|
+
case obj
|
15
|
+
when Hash
|
16
|
+
obj.transform_values do |val|
|
17
|
+
val.is_a?(Hash) && val.key?("lines") ? val["lines"] : remove_lines_key(val)
|
18
|
+
end
|
19
|
+
else
|
20
|
+
obj
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# overwrite
|
25
|
+
File.write(filename, JSON.generate(remove_lines_key(contents)))
|
26
|
+
|
27
|
+
puts Dir['coverage/.*.json']
|
data/bin/test
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
set -e
|
4
|
+
|
5
|
+
RUBY_V=$(ruby -v)
|
6
|
+
|
7
|
+
function reset_gemfile_and_test {
|
8
|
+
rm Gemfile.lock
|
9
|
+
|
10
|
+
eval "$1 bundle update"
|
11
|
+
eval "$1 bundle exec rake test"
|
12
|
+
}
|
13
|
+
|
14
|
+
function test_with_activemodel {
|
15
|
+
reset_gemfile_and_test "ACTIVEMODEL_VERSION=$1"
|
16
|
+
}
|
17
|
+
|
18
|
+
RUBY_2_2345="ruby 2.[2345]."
|
19
|
+
RUBY_2_234="ruby 2.[234]."
|
20
|
+
RUBY_2_567="ruby 2.[567]."
|
21
|
+
RUBY_2_2="ruby 2.2."
|
22
|
+
RUBY_3_X="ruby 3.0."
|
23
|
+
|
24
|
+
if [[ $RUBY_V =~ $RUBY_2_2345 ]]; then
|
25
|
+
if [[ $RUBY_V =~ $RUBY_2_234 ]]; then
|
26
|
+
reset_gemfile_and_test
|
27
|
+
fi
|
28
|
+
|
29
|
+
if [[ $RUBY_V =~ $RUBY_2_2 ]]; then
|
30
|
+
test_with_activemodel "3.2"
|
31
|
+
fi
|
32
|
+
|
33
|
+
test_with_activemodel "4.0"
|
34
|
+
test_with_activemodel "4.1"
|
35
|
+
test_with_activemodel "4.2"
|
36
|
+
test_with_activemodel "5.0"
|
37
|
+
test_with_activemodel "5.1"
|
38
|
+
test_with_activemodel "5.2"
|
39
|
+
fi
|
40
|
+
|
41
|
+
if [[ $RUBY_V =~ $RUBY_2_567 ]] || [[ $RUBY_V =~ $RUBY_3_X ]]; then
|
42
|
+
gem install bundler -v ">= 2" --no-doc
|
43
|
+
|
44
|
+
reset_gemfile_and_test
|
45
|
+
|
46
|
+
test_with_activemodel "6.0"
|
47
|
+
test_with_activemodel "6.1"
|
48
|
+
fi
|
@@ -35,10 +35,10 @@ module Micro::Attributes
|
|
35
35
|
|
36
36
|
KeepProc = -> validation_data { validation_data[0] == :accept && validation_data[1] == Proc }
|
37
37
|
|
38
|
-
def __attribute_assign(key,
|
38
|
+
def __attribute_assign(key, init_hash, attribute_data)
|
39
39
|
validation_data = attribute_data[1]
|
40
40
|
|
41
|
-
value_to_assign = FetchValueToAssign.(
|
41
|
+
value_to_assign = FetchValueToAssign.(init_hash, init_hash[key], attribute_data, KeepProc.(validation_data))
|
42
42
|
|
43
43
|
value = __attributes[key] = instance_variable_set("@#{key}", value_to_assign)
|
44
44
|
|
@@ -179,6 +179,16 @@ module Micro
|
|
179
179
|
__attribute_assign(name, false, options)
|
180
180
|
end
|
181
181
|
|
182
|
+
RaiseKindError = ->(expected, given) do
|
183
|
+
if (util = Kind.const_get(:KIND, false)) && util.respond_to?(:error!)
|
184
|
+
util.error!(expected, given)
|
185
|
+
else
|
186
|
+
raise Kind::Error.new(expected, given, label: nil)
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
private_constant :RaiseKindError
|
191
|
+
|
182
192
|
def attributes(*args)
|
183
193
|
return __attributes.to_a if args.empty?
|
184
194
|
|
@@ -191,7 +201,7 @@ module Micro
|
|
191
201
|
if arg.is_a?(String) || arg.is_a?(Symbol)
|
192
202
|
__attribute_assign(arg, false, options)
|
193
203
|
else
|
194
|
-
|
204
|
+
RaiseKindError.call('String/Symbol'.freeze, arg)
|
195
205
|
end
|
196
206
|
end
|
197
207
|
end
|
data/lib/micro/attributes.rb
CHANGED
@@ -123,12 +123,16 @@ module Micro
|
|
123
123
|
@__attributes ||= {}
|
124
124
|
end
|
125
125
|
|
126
|
-
FetchValueToAssign = -> (value, attribute_data, keep_proc = false) do
|
126
|
+
FetchValueToAssign = -> (init_hash, value, attribute_data, keep_proc = false) do
|
127
127
|
default = attribute_data[0]
|
128
128
|
|
129
129
|
value_to_assign =
|
130
130
|
if default.is_a?(Proc) && !keep_proc
|
131
|
-
default.arity
|
131
|
+
case default.arity
|
132
|
+
when 0 then default.call
|
133
|
+
when 2 then default.call(value, init_hash)
|
134
|
+
else default.call(value)
|
135
|
+
end
|
132
136
|
else
|
133
137
|
value.nil? ? default : value
|
134
138
|
end
|
@@ -143,14 +147,14 @@ module Micro
|
|
143
147
|
|
144
148
|
def __attributes_assign(hash)
|
145
149
|
self.class.__attributes_data__.each do |name, attribute_data|
|
146
|
-
__attribute_assign(name, hash
|
150
|
+
__attribute_assign(name, hash, attribute_data) if attribute?(name, true)
|
147
151
|
end
|
148
152
|
|
149
153
|
__attributes.freeze
|
150
154
|
end
|
151
155
|
|
152
|
-
def __attribute_assign(name,
|
153
|
-
value_to_assign = FetchValueToAssign.(
|
156
|
+
def __attribute_assign(name, init_hash, attribute_data)
|
157
|
+
value_to_assign = FetchValueToAssign.(init_hash, init_hash[name], attribute_data)
|
154
158
|
|
155
159
|
ivar_value = instance_variable_set("@#{name}", value_to_assign)
|
156
160
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: u-attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Serradura
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kind
|
@@ -67,16 +67,18 @@ executables: []
|
|
67
67
|
extensions: []
|
68
68
|
extra_rdoc_files: []
|
69
69
|
files:
|
70
|
+
- ".github/workflows/ci.yml"
|
70
71
|
- ".gitignore"
|
71
|
-
- ".
|
72
|
-
- ".travis.yml"
|
72
|
+
- ".vscode/settings.json"
|
73
73
|
- CODE_OF_CONDUCT.md
|
74
74
|
- Gemfile
|
75
75
|
- LICENSE.txt
|
76
76
|
- README.md
|
77
77
|
- Rakefile
|
78
78
|
- bin/console
|
79
|
+
- bin/prepare_coverage
|
79
80
|
- bin/setup
|
81
|
+
- bin/test
|
80
82
|
- lib/micro/attributes.rb
|
81
83
|
- lib/micro/attributes/diff.rb
|
82
84
|
- lib/micro/attributes/features.rb
|
@@ -91,13 +93,12 @@ files:
|
|
91
93
|
- lib/micro/attributes/utils.rb
|
92
94
|
- lib/micro/attributes/version.rb
|
93
95
|
- lib/u-attributes.rb
|
94
|
-
- test.sh
|
95
96
|
- u-attributes.gemspec
|
96
97
|
homepage: https://github.com/serradura/u-attributes
|
97
98
|
licenses:
|
98
99
|
- MIT
|
99
100
|
metadata: {}
|
100
|
-
post_install_message:
|
101
|
+
post_install_message:
|
101
102
|
rdoc_options: []
|
102
103
|
require_paths:
|
103
104
|
- lib
|
@@ -112,8 +113,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
113
|
- !ruby/object:Gem::Version
|
113
114
|
version: '0'
|
114
115
|
requirements: []
|
115
|
-
rubygems_version: 3.
|
116
|
-
signing_key:
|
116
|
+
rubygems_version: 3.2.17
|
117
|
+
signing_key:
|
117
118
|
specification_version: 4
|
118
119
|
summary: Create "immutable" objects with no setters, just getters.
|
119
120
|
test_files: []
|
data/.travis.sh
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
|
3
|
-
RUBY_V=$(ruby -v)
|
4
|
-
|
5
|
-
function run_with_bundler {
|
6
|
-
rm Gemfile.lock
|
7
|
-
|
8
|
-
if [ ! -z "$1" ]; then
|
9
|
-
bundle_cmd="bundle _$1_"
|
10
|
-
else
|
11
|
-
bundle_cmd="bundle"
|
12
|
-
fi
|
13
|
-
|
14
|
-
eval "$2 $bundle_cmd update"
|
15
|
-
eval "$2 $bundle_cmd exec rake test"
|
16
|
-
}
|
17
|
-
|
18
|
-
function run_with_am_version_and_bundler {
|
19
|
-
run_with_bundler "$2" "ACTIVEMODEL_VERSION=$1"
|
20
|
-
}
|
21
|
-
|
22
|
-
RUBY_2_2345="ruby 2.[2345]."
|
23
|
-
|
24
|
-
if [[ $RUBY_V =~ $RUBY_2_2345 ]]; then
|
25
|
-
run_with_bundler "$BUNDLER_V1"
|
26
|
-
|
27
|
-
run_with_am_version_and_bundler "3.2" "$BUNDLER_V1"
|
28
|
-
run_with_am_version_and_bundler "4.0" "$BUNDLER_V1"
|
29
|
-
run_with_am_version_and_bundler "4.1" "$BUNDLER_V1"
|
30
|
-
run_with_am_version_and_bundler "4.2" "$BUNDLER_V1"
|
31
|
-
run_with_am_version_and_bundler "5.0" "$BUNDLER_V1"
|
32
|
-
run_with_am_version_and_bundler "5.1" "$BUNDLER_V1"
|
33
|
-
run_with_am_version_and_bundler "5.2" "$BUNDLER_V1"
|
34
|
-
fi
|
35
|
-
|
36
|
-
RUBY_2_567="ruby 2.[567]."
|
37
|
-
RUBY_3_x_x="ruby 3.0."
|
38
|
-
|
39
|
-
if [[ $RUBY_V =~ $RUBY_2_567 ]] || [[ $RUBY_V =~ $RUBY_3_x_x ]]; then
|
40
|
-
gem install bundler -v ">= 2" --no-doc
|
41
|
-
|
42
|
-
run_with_bundler
|
43
|
-
run_with_am_version_and_bundler "6.0"
|
44
|
-
run_with_am_version_and_bundler "6.1"
|
45
|
-
fi
|
data/.travis.yml
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
language: ruby
|
2
|
-
|
3
|
-
cache:
|
4
|
-
bundler: true
|
5
|
-
directories:
|
6
|
-
- /home/travis/.rvm/
|
7
|
-
|
8
|
-
rvm:
|
9
|
-
- 2.2.2
|
10
|
-
- 2.3.0
|
11
|
-
- 2.4.0
|
12
|
-
- 2.5.0
|
13
|
-
- 2.6.0
|
14
|
-
- 2.7.0
|
15
|
-
- 3.0.0
|
16
|
-
|
17
|
-
env:
|
18
|
-
- BUNDLER_V1="1.17.3"
|
19
|
-
|
20
|
-
before_install:
|
21
|
-
- gem install bundler -v "$BUNDLER_V1"
|
22
|
-
|
23
|
-
install: bundle install --jobs=3 --retry=3
|
24
|
-
|
25
|
-
before_script:
|
26
|
-
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
27
|
-
- chmod +x ./cc-test-reporter
|
28
|
-
- "./cc-test-reporter before-build"
|
29
|
-
|
30
|
-
script: "./.travis.sh"
|
31
|
-
|
32
|
-
after_success:
|
33
|
-
- "./cc-test-reporter after-build -t simplecov"
|