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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 484a7b770e8ae7dd141c7538e2bc50c1b82beb63e24ee53dd9f9445cbd91f057
4
- data.tar.gz: 3d555771a3deba711dc4995cd12674461b94c82e65ccbdd9bba215d354adaa52
3
+ metadata.gz: c330847c820a244e35afcd702510d791a72822677ad97a4050b37dc0a9653a00
4
+ data.tar.gz: 66f7e86e1c1579f64d39e77c54eac7fab03551dbbc8fd6ce02438fab817c0939
5
5
  SHA512:
6
- metadata.gz: fc5f65eb1a10c5172f0b6a1fa5296f4470e024fa42559cfe0d64d89d0a07c0c203ae28ce1b66afae741669a8073b1c6cbb7d05d5373874946afefca6620d7874
7
- data.tar.gz: db8895b0a85d803de7ec04f81fc83fb98eac4b487ed4224e7fb7b6bda3d66293758ce416341dddbd40ae630dfb96d4d26cdd380990a3fca2580df931b459311a
6
+ metadata.gz: d06af39a1601f4ba9496e5daec023cb13d1944f0ab2b986320a365788df2208fecf1122c73d023c669647fb3f826eca15d0f4bf132872c6b84459bd13c8037ce
7
+ data.tar.gz: 16bd3897ce372901db54506761dffbc3ba42a72e6700fabc0db83fedad6ab8eaf9bb69f1d98c26e4c0eee809311d51926431807fde187af3b80a6cdba2d73f78
data/.travis.sh CHANGED
@@ -1,31 +1,45 @@
1
1
  #!/bin/bash
2
2
 
3
- bundle exec rake test
3
+ RUBY_V=$(ruby -v)
4
4
 
5
- ACTIVEMODEL_VERSION='3.2' bundle update
6
- ACTIVEMODEL_VERSION='3.2' bundle exec rake test
5
+ function run_with_bundler {
6
+ rm Gemfile.lock
7
7
 
8
- ACTIVEMODEL_VERSION='4.0' bundle update
9
- ACTIVEMODEL_VERSION='4.0' bundle exec rake test
8
+ if [ ! -z "$1" ]; then
9
+ bundle_cmd="bundle _$1_"
10
+ else
11
+ bundle_cmd="bundle"
12
+ fi
10
13
 
11
- ACTIVEMODEL_VERSION='4.1' bundle update
12
- ACTIVEMODEL_VERSION='4.1' bundle exec rake test
14
+ eval "$2 $bundle_cmd update"
15
+ eval "$2 $bundle_cmd exec rake test"
16
+ }
13
17
 
14
- ACTIVEMODEL_VERSION='4.2' bundle update
15
- ACTIVEMODEL_VERSION='4.2' bundle exec rake test
18
+ function run_with_am_version_and_bundler {
19
+ run_with_bundler "$2" "ACTIVEMODEL_VERSION=$1"
20
+ }
16
21
 
17
- ACTIVEMODEL_VERSION='5.0' bundle update
18
- ACTIVEMODEL_VERSION='5.0' bundle exec rake test
22
+ RUBY_2_2345="ruby 2.[2345]."
19
23
 
20
- ACTIVEMODEL_VERSION='5.1' bundle update
21
- ACTIVEMODEL_VERSION='5.1' bundle exec rake test
24
+ if [[ $RUBY_V =~ $RUBY_2_2345 ]]; then
25
+ run_with_bundler "$BUNDLER_V1"
22
26
 
23
- if [[ ! $ruby_v =~ '2.2.0' ]]; then
24
- ACTIVEMODEL_VERSION='5.2' bundle update
25
- ACTIVEMODEL_VERSION='5.2' bundle exec rake test
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
- if [[ $ruby_v =~ '2.5.' ]] || [[ $ruby_v =~ '2.6.' ]] || [[ $ruby_v =~ '2.7.' ]]; then
29
- ACTIVEMODEL_VERSION='6.0' bundle update
30
- ACTIVEMODEL_VERSION='6.0' bundle exec rake test
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
- - truffleruby-head
15
+ - 3.0.0
11
16
 
12
- cache: bundler
17
+ env:
18
+ - BUNDLER_V1="1.17.3"
13
19
 
14
20
  before_install:
15
- - gem uninstall -v '>= 2' -i $(rvm gemdir)@global -ax bundler || true
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
- - './cc-test-reporter before-build'
28
+ - "./cc-test-reporter before-build"
24
29
 
25
- script: './.travis.sh'
30
+ script: "./.travis.sh"
26
31
 
27
32
  after_success:
28
- - './cc-test-reporter after-build -t simplecov'
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.fetch('ACTIVEMODEL_VERSION', '6.1')
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.3'
15
- when '6.0' then '6.0.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 '~> 0.17.1'
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
- gem 'minitest', activemodel_version < '4.1' ? '~> 4.2' : '~> 5.0'
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. No setters, just getters!</i></p>
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-2.2+-ruby.svg?colorA=99004d&colorB=cc0066" alt="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, and your objects will have only getters and no setters.
29
- So, if you change [[1](#with_attribute)] [[2](#with_attributes)] some object attribute, you will have a new object instance. That is, you transform the object instead of modifying it.
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
- | 2.6.0 | main | >= 2.2.0 | >= 3.2, < 6.1 |
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::Of.(@from_class, to)
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::Of.(::Symbol, value)
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
- Utils::Hashes.kind(hash)
21
+ Kind::Hash[hash]
22
22
  end
23
23
  end
24
24
 
@@ -191,7 +191,7 @@ module Micro
191
191
  if arg.is_a?(String) || arg.is_a?(Symbol)
192
192
  __attribute_assign(arg, false, options)
193
193
  else
194
- raise Kind::Error.new('String/Symbol'.freeze, arg)
194
+ Kind::KIND.error!('String/Symbol'.freeze, arg)
195
195
  end
196
196
  end
197
197
  end
@@ -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
- def self.stringify_keys(arg)
11
- hash = kind(arg)
5
+ module Hashes
6
+ extend self
12
7
 
13
- return hash if hash.empty?
14
- return hash.transform_keys(&:to_s) if hash.respond_to?(:transform_keys)
8
+ def stringify_keys(arg)
9
+ hash = Kind::Hash[arg]
15
10
 
16
- hash.each_with_object({}) { |(key, val), memo| memo[key.to_s] = val }
17
- end
11
+ return hash if hash.empty?
12
+ return hash.transform_keys(&:to_s) if hash.respond_to?(:transform_keys)
18
13
 
19
- def self.symbolize_keys(arg)
20
- hash = kind(arg)
14
+ hash.each_with_object({}) { |(key, val), memo| memo[key.to_s] = val }
15
+ end
21
16
 
22
- return hash if hash.empty?
23
- return hash.transform_keys(&:to_sym) if hash.respond_to?(:transform_keys)
17
+ def symbolize_keys(arg)
18
+ hash = Kind::Hash[arg]
24
19
 
25
- hash.each_with_object({}) { |(key, val), memo| memo[key.to_sym] = val }
26
- end
20
+ return hash if hash.empty?
21
+ return hash.transform_keys(&:to_sym) if hash.respond_to?(:transform_keys)
27
22
 
28
- def self.keys_as(type, hash)
29
- return kind(hash) unless type
23
+ hash.each_with_object({}) { |(key, val), memo| memo[key.to_sym] = val }
24
+ end
30
25
 
31
- return symbolize_keys(hash) if type == Symbol || type == :symbol
32
- return stringify_keys(hash) if type == String || type == :string
26
+ def keys_as(type, hash)
27
+ return Kind::Hash[hash] unless type
33
28
 
34
- raise ArgumentError, 'argument must be one of these values: :symbol, :string, Symbol, String'.freeze
35
- end
29
+ return symbolize_keys(hash) if type == Symbol || type == :symbol
30
+ return stringify_keys(hash) if type == String || type == :string
36
31
 
37
- def self.assoc(hash, key)
38
- value = hash[key.to_s]
32
+ raise ArgumentError, 'argument must be one of these values: :symbol, :string, Symbol, String'.freeze
33
+ end
39
34
 
40
- value.nil? ? hash[key.to_sym] : value
41
- end
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
- module ExtractAttribute
45
- def self.call(object, key:)
46
- return object.public_send(key) if object.respond_to?(key)
42
+ module ExtractAttribute
43
+ def self.call(object, key:)
44
+ return object.public_send(key) if object.respond_to?(key)
47
45
 
48
- Hashes.assoc(object, key) if object.respond_to?(:[])
49
- end
46
+ Hashes.assoc(object, key) if object.respond_to?(:[])
47
+ end
50
48
 
51
- def self.from(object, keys:)
52
- Kind::Of.(::Array, keys).each_with_object({}) do |key, memo|
53
- memo[key] = call(object, key: key)
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Micro
4
4
  module Attributes
5
- VERSION = '2.6.0'.freeze
5
+ VERSION = '2.7.0'.freeze
6
6
  end
7
7
  end
data/test.sh CHANGED
@@ -1,7 +1,11 @@
1
1
  #!/bin/bash
2
2
 
3
- git checkout -- Gemfile.lock
4
-
5
3
  source $(dirname $0)/.travis.sh
6
4
 
7
- git checkout -- Gemfile.lock
5
+ echo ''
6
+ echo 'Resetting Gemfile'
7
+ echo ''
8
+
9
+ rm Gemfile.lock
10
+
11
+ bundle
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. No setters, just getters!}
12
+ spec.summary = %q{Create "immutable" objects with no setters, just getters.}
13
13
  spec.description =
14
- "This gem allows you to define \"immutable\" objects, and your objects will have only getters and no setters. "\
15
- "So, if you change some object attribute, you will have a new object instance. " \
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', '>= 3.0', '< 5.0'
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.6.0
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: 2020-09-23 00:00:00.000000000 Z
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: '3.0'
19
+ version: '4.0'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.0'
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: '3.0'
29
+ version: '4.0'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.0'
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, and your objects will
62
- have only getters and no setters. So, if you change some object attribute, you will
63
- have a new object instance. That is, you transform the object instead of modifying
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.0.6
115
+ rubygems_version: 3.1.4
117
116
  signing_key:
118
117
  specification_version: 4
119
- summary: Create "immutable" objects. No setters, just getters!
118
+ summary: Create "immutable" objects with no setters, just getters.
120
119
  test_files: []