u-attributes 2.6.0 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.sh +33 -19
- data/.travis.yml +12 -7
- data/Gemfile +15 -10
- data/README.md +14 -5
- data/lib/micro/attributes/diff.rb +1 -1
- data/lib/micro/attributes/features/keys_as_symbol.rb +2 -2
- data/lib/micro/attributes/macros.rb +1 -1
- data/lib/micro/attributes/utils.rb +35 -37
- data/lib/micro/attributes/version.rb +1 -1
- data/test.sh +7 -3
- data/u-attributes.gemspec +4 -5
- metadata +11 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c330847c820a244e35afcd702510d791a72822677ad97a4050b37dc0a9653a00
|
4
|
+
data.tar.gz: 66f7e86e1c1579f64d39e77c54eac7fab03551dbbc8fd6ce02438fab817c0939
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d06af39a1601f4ba9496e5daec023cb13d1944f0ab2b986320a365788df2208fecf1122c73d023c669647fb3f826eca15d0f4bf132872c6b84459bd13c8037ce
|
7
|
+
data.tar.gz: 16bd3897ce372901db54506761dffbc3ba42a72e6700fabc0db83fedad6ab8eaf9bb69f1d98c26e4c0eee809311d51926431807fde187af3b80a6cdba2d73f78
|
data/.travis.sh
CHANGED
@@ -1,31 +1,45 @@
|
|
1
1
|
#!/bin/bash
|
2
2
|
|
3
|
-
|
3
|
+
RUBY_V=$(ruby -v)
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
function run_with_bundler {
|
6
|
+
rm Gemfile.lock
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
if [ ! -z "$1" ]; then
|
9
|
+
bundle_cmd="bundle _$1_"
|
10
|
+
else
|
11
|
+
bundle_cmd="bundle"
|
12
|
+
fi
|
10
13
|
|
11
|
-
|
12
|
-
|
14
|
+
eval "$2 $bundle_cmd update"
|
15
|
+
eval "$2 $bundle_cmd exec rake test"
|
16
|
+
}
|
13
17
|
|
14
|
-
|
15
|
-
|
18
|
+
function run_with_am_version_and_bundler {
|
19
|
+
run_with_bundler "$2" "ACTIVEMODEL_VERSION=$1"
|
20
|
+
}
|
16
21
|
|
17
|
-
|
18
|
-
ACTIVEMODEL_VERSION='5.0' bundle exec rake test
|
22
|
+
RUBY_2_2345="ruby 2.[2345]."
|
19
23
|
|
20
|
-
|
21
|
-
|
24
|
+
if [[ $RUBY_V =~ $RUBY_2_2345 ]]; then
|
25
|
+
run_with_bundler "$BUNDLER_V1"
|
22
26
|
|
23
|
-
|
24
|
-
|
25
|
-
|
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"
|
26
34
|
fi
|
27
35
|
|
28
|
-
|
29
|
-
|
30
|
-
|
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"
|
31
45
|
fi
|
data/.travis.yml
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
|
+
cache:
|
4
|
+
bundler: true
|
5
|
+
directories:
|
6
|
+
- /home/travis/.rvm/
|
7
|
+
|
3
8
|
rvm:
|
4
9
|
- 2.2.2
|
5
10
|
- 2.3.0
|
@@ -7,22 +12,22 @@ rvm:
|
|
7
12
|
- 2.5.0
|
8
13
|
- 2.6.0
|
9
14
|
- 2.7.0
|
10
|
-
-
|
15
|
+
- 3.0.0
|
11
16
|
|
12
|
-
|
17
|
+
env:
|
18
|
+
- BUNDLER_V1="1.17.3"
|
13
19
|
|
14
20
|
before_install:
|
15
|
-
- gem
|
16
|
-
- gem install bundler -v '< 2'
|
21
|
+
- gem install bundler -v "$BUNDLER_V1"
|
17
22
|
|
18
23
|
install: bundle install --jobs=3 --retry=3
|
19
24
|
|
20
25
|
before_script:
|
21
26
|
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
22
27
|
- chmod +x ./cc-test-reporter
|
23
|
-
-
|
28
|
+
- "./cc-test-reporter before-build"
|
24
29
|
|
25
|
-
script:
|
30
|
+
script: "./.travis.sh"
|
26
31
|
|
27
32
|
after_success:
|
28
|
-
-
|
33
|
+
- "./cc-test-reporter after-build -t simplecov"
|
data/Gemfile
CHANGED
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gem 'u-case', '~> 4.0'
|
4
4
|
|
5
|
-
activemodel_version = ENV
|
5
|
+
activemodel_version = ENV['ACTIVEMODEL_VERSION']
|
6
6
|
|
7
7
|
activemodel = case activemodel_version
|
8
8
|
when '3.2' then '3.2.22'
|
@@ -11,26 +11,31 @@ activemodel = case activemodel_version
|
|
11
11
|
when '4.2' then '4.2.11'
|
12
12
|
when '5.0' then '5.0.7'
|
13
13
|
when '5.1' then '5.1.7'
|
14
|
-
when '5.2' then '5.2.
|
15
|
-
when '6.0' then '6.0.
|
14
|
+
when '5.2' then '5.2.4'
|
15
|
+
when '6.0' then '6.0.3.4'
|
16
|
+
when '6.1' then '6.1.2'
|
16
17
|
end
|
17
18
|
|
18
|
-
if activemodel_version < '6.1'
|
19
|
-
gem 'activemodel', activemodel, require: false
|
20
|
-
gem 'activesupport', activemodel, require: false
|
21
|
-
end
|
22
|
-
|
23
19
|
simplecov_version =
|
24
20
|
case RUBY_VERSION
|
25
|
-
when /\A2.[23]/ then '
|
21
|
+
when /\A2.[23]/ then '0.17.1'
|
26
22
|
when /\A2.4/ then '~> 0.18.5'
|
27
23
|
else '~> 0.19'
|
28
24
|
end
|
29
25
|
|
30
26
|
group :test do
|
31
|
-
|
27
|
+
if activemodel_version
|
28
|
+
gem 'activesupport', activemodel, require: false
|
29
|
+
gem 'activemodel', activemodel, require: false
|
30
|
+
gem 'minitest', activemodel_version < '4.1' ? '~> 4.2' : '~> 5.0'
|
31
|
+
else
|
32
|
+
gem 'minitest', '~> 5.0'
|
33
|
+
end
|
34
|
+
|
32
35
|
gem 'simplecov', simplecov_version, require: false
|
33
36
|
end
|
34
37
|
|
38
|
+
gem 'rake', '~> 13.0'
|
39
|
+
|
35
40
|
# Specify your gem's dependencies in u-attributes.gemspec
|
36
41
|
gemspec
|
data/README.md
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
<p align="center">
|
2
2
|
<img src="./assets/u-attributes_logo_v1.png" alt='Create "immutable" objects. No setters, just getters!'>
|
3
3
|
|
4
|
-
<p align="center"><i>Create "immutable" objects
|
4
|
+
<p align="center"><i>Create "immutable" objects with no setters, just getters.</i></p>
|
5
5
|
<br>
|
6
6
|
</p>
|
7
7
|
|
8
8
|
<p align="center">
|
9
|
-
<img src="https://img.shields.io/badge/ruby
|
9
|
+
<img src="https://img.shields.io/badge/ruby->%3D%202.2.0-ruby.svg?colorA=99004d&colorB=cc0066" alt="Ruby">
|
10
10
|
|
11
11
|
<a href="https://rubygems.org/gems/u-attributes">
|
12
12
|
<img alt="Gem" src="https://img.shields.io/gem/v/u-attributes.svg?style=flat-square">
|
@@ -25,8 +25,16 @@
|
|
25
25
|
</a>
|
26
26
|
</p>
|
27
27
|
|
28
|
-
This gem allows you to define "immutable" objects,
|
29
|
-
So, if you change [[1](#with_attribute)] [[2](#with_attributes)]
|
28
|
+
This gem allows you to define "immutable" objects, when using it your objects will only have getters and no setters.
|
29
|
+
So, if you change [[1](#with_attribute)] [[2](#with_attributes)] an attribute of the object, you’ll have a new object instance. That is, you transform the object instead of modifying it.
|
30
|
+
|
31
|
+
## Documentation <!-- omit in toc -->
|
32
|
+
|
33
|
+
Version | Documentation
|
34
|
+
---------- | -------------
|
35
|
+
unreleased | https://github.com/serradura/u-case/blob/main/README.md
|
36
|
+
2.7.0 | https://github.com/serradura/u-case/blob/v2.x/README.md
|
37
|
+
1.2.0 | https://github.com/serradura/u-case/blob/v1.x/README.md
|
30
38
|
|
31
39
|
# Table of contents <!-- omit in toc -->
|
32
40
|
- [Installation](#installation)
|
@@ -85,7 +93,8 @@ gem 'u-attributes'
|
|
85
93
|
|
86
94
|
| u-attributes | branch | ruby | activemodel |
|
87
95
|
| -------------- | ------- | -------- | ------------- |
|
88
|
-
|
|
96
|
+
| unreleased | main | >= 2.2.0 | >= 3.2, < 7 |
|
97
|
+
| 2.7.0 | v2.x | >= 2.2.0 | >= 3.2, < 7 |
|
89
98
|
| 1.2.0 | v1.x | >= 2.2.0 | >= 3.2, < 6.1 |
|
90
99
|
|
91
100
|
> **Note**: The activemodel is an optional dependency, this module [can be enabled](#activemodelvalidation-extension) to validate the attributes.
|
@@ -12,7 +12,7 @@ module Micro::Attributes
|
|
12
12
|
def initialize(from:, to:)
|
13
13
|
@from_class = from.class
|
14
14
|
|
15
|
-
@from, @to = from, Kind
|
15
|
+
@from, @to = from, Kind.of(@from_class, to)
|
16
16
|
|
17
17
|
@from_key, @to_key =
|
18
18
|
@from_class.attributes_access == :symbol ? FROM_TO_SYM : FROM_TO_STR
|
@@ -10,7 +10,7 @@ module Micro::Attributes
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def __attribute_key_check__(value)
|
13
|
-
Kind::
|
13
|
+
Kind::Symbol[value]
|
14
14
|
end
|
15
15
|
|
16
16
|
def __attribute_key_transform__(value)
|
@@ -18,7 +18,7 @@ module Micro::Attributes
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def __attributes_keys_transform__(hash)
|
21
|
-
|
21
|
+
Kind::Hash[hash]
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -1,58 +1,56 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
module Micro::Attributes
|
4
|
-
module Utils
|
5
|
-
module Hashes
|
6
|
-
def self.kind(hash)
|
7
|
-
Kind::Of.(::Hash, hash)
|
8
|
-
end
|
3
|
+
module Micro::Attributes::Utils
|
9
4
|
|
10
|
-
|
11
|
-
|
5
|
+
module Hashes
|
6
|
+
extend self
|
12
7
|
|
13
|
-
|
14
|
-
|
8
|
+
def stringify_keys(arg)
|
9
|
+
hash = Kind::Hash[arg]
|
15
10
|
|
16
|
-
|
17
|
-
|
11
|
+
return hash if hash.empty?
|
12
|
+
return hash.transform_keys(&:to_s) if hash.respond_to?(:transform_keys)
|
18
13
|
|
19
|
-
|
20
|
-
|
14
|
+
hash.each_with_object({}) { |(key, val), memo| memo[key.to_s] = val }
|
15
|
+
end
|
21
16
|
|
22
|
-
|
23
|
-
|
17
|
+
def symbolize_keys(arg)
|
18
|
+
hash = Kind::Hash[arg]
|
24
19
|
|
25
|
-
|
26
|
-
|
20
|
+
return hash if hash.empty?
|
21
|
+
return hash.transform_keys(&:to_sym) if hash.respond_to?(:transform_keys)
|
27
22
|
|
28
|
-
|
29
|
-
|
23
|
+
hash.each_with_object({}) { |(key, val), memo| memo[key.to_sym] = val }
|
24
|
+
end
|
30
25
|
|
31
|
-
|
32
|
-
|
26
|
+
def keys_as(type, hash)
|
27
|
+
return Kind::Hash[hash] unless type
|
33
28
|
|
34
|
-
|
35
|
-
|
29
|
+
return symbolize_keys(hash) if type == Symbol || type == :symbol
|
30
|
+
return stringify_keys(hash) if type == String || type == :string
|
36
31
|
|
37
|
-
|
38
|
-
|
32
|
+
raise ArgumentError, 'argument must be one of these values: :symbol, :string, Symbol, String'.freeze
|
33
|
+
end
|
39
34
|
|
40
|
-
|
41
|
-
|
35
|
+
def assoc(hash, key)
|
36
|
+
value = hash[key.to_s]
|
37
|
+
|
38
|
+
value.nil? ? hash[key.to_sym] : value
|
42
39
|
end
|
40
|
+
end
|
43
41
|
|
44
|
-
|
45
|
-
|
46
|
-
|
42
|
+
module ExtractAttribute
|
43
|
+
def self.call(object, key:)
|
44
|
+
return object.public_send(key) if object.respond_to?(key)
|
47
45
|
|
48
|
-
|
49
|
-
|
46
|
+
Hashes.assoc(object, key) if object.respond_to?(:[])
|
47
|
+
end
|
50
48
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
end
|
49
|
+
def self.from(object, keys:)
|
50
|
+
Kind::Array[keys].each_with_object({}) do |key, memo|
|
51
|
+
memo[key] = call(object, key: key)
|
55
52
|
end
|
56
53
|
end
|
57
54
|
end
|
55
|
+
|
58
56
|
end
|
data/test.sh
CHANGED
data/u-attributes.gemspec
CHANGED
@@ -9,11 +9,10 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ['Rodrigo Serradura']
|
10
10
|
spec.email = ['rodrigo.serradura@gmail.com']
|
11
11
|
|
12
|
-
spec.summary = %q{Create "immutable" objects
|
12
|
+
spec.summary = %q{Create "immutable" objects with no setters, just getters.}
|
13
13
|
spec.description =
|
14
|
-
|
15
|
-
|
16
|
-
"That is, you transform the object instead of modifying it."
|
14
|
+
'This gem allows you to define "immutable" objects, when using it your objects will only have getters and no setters.' \
|
15
|
+
'So, if you change an attribute of the object, you’ll have a new object instance.'
|
17
16
|
spec.homepage = 'https://github.com/serradura/u-attributes'
|
18
17
|
spec.license = 'MIT'
|
19
18
|
|
@@ -28,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
28
27
|
|
29
28
|
spec.required_ruby_version = '>= 2.2.0'
|
30
29
|
|
31
|
-
spec.add_runtime_dependency 'kind', '>=
|
30
|
+
spec.add_runtime_dependency 'kind', '>= 4.0', '< 6.0'
|
32
31
|
|
33
32
|
spec.add_development_dependency 'bundler'
|
34
33
|
spec.add_development_dependency 'rake', '~> 13.0'
|
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.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rodrigo Serradura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: kind
|
@@ -16,20 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '4.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '6.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '4.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '6.0'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: bundler
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,10 +58,9 @@ dependencies:
|
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
60
|
version: '13.0'
|
61
|
-
description: This gem allows you to define "immutable" objects,
|
62
|
-
|
63
|
-
have a new object instance.
|
64
|
-
it.
|
61
|
+
description: This gem allows you to define "immutable" objects, when using it your
|
62
|
+
objects will only have getters and no setters.So, if you change an attribute of
|
63
|
+
the object, you’ll have a new object instance.
|
65
64
|
email:
|
66
65
|
- rodrigo.serradura@gmail.com
|
67
66
|
executables: []
|
@@ -113,8 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
112
|
- !ruby/object:Gem::Version
|
114
113
|
version: '0'
|
115
114
|
requirements: []
|
116
|
-
rubygems_version: 3.
|
115
|
+
rubygems_version: 3.1.4
|
117
116
|
signing_key:
|
118
117
|
specification_version: 4
|
119
|
-
summary: Create "immutable" objects
|
118
|
+
summary: Create "immutable" objects with no setters, just getters.
|
120
119
|
test_files: []
|