attr_extras 6.2.5 → 7.0.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: a01c4bfc2a6ce3f1ae8735fe122b7abbd65c99be5a17330087e09e028e59b3cb
4
- data.tar.gz: c83abb5d1467b7c91b2ff0c54220fa72ebdc2d6ee0deba2c7ca8edc3629f744c
3
+ metadata.gz: e5fd3ea490025e4ed3942658efff5b14335b261d843dead16fedd3f75fe9ca2c
4
+ data.tar.gz: 1adcf6c8e345de200ba9d0798caa4d996a62fb76ebcbe4ad2d167a996e98dacd
5
5
  SHA512:
6
- metadata.gz: 48893855229adec5435cd0b709c50cf1e631e321197dd23baeaaa54e11c513f1d4f47ac3e9b3ab2268fc6d86c26c519e57c8e12d9c7aa2a7e819e9c5a53d9cfd
7
- data.tar.gz: dc63a635eedac54ce49b25eece473e5264b655d2c87852725bc28baeaf4f9c7d516febad45978ba71816c3dec0afc1e5e114c9587c16ad890999a408efe588cd
6
+ metadata.gz: ba168966ed66c2369fd23e1a11505ea06b0c559ce874492ec9744240505d6fbc3af2a13fc91b0e4ed4b51ff0768fd67c51fb24b6ed2ae5181fe71194ce304159
7
+ data.tar.gz: 37696980e733441e426e0102e2e8473b61206ef95be7a761197d5ed41571f2ead7304313a8c49d810b00eed4f21b485be1b0011ef3e5aa77a2efdde32852a598
@@ -0,0 +1,8 @@
1
+ version: 2
2
+ updates:
3
+
4
+ - package-ecosystem: "github-actions"
5
+ directory: "/"
6
+ schedule:
7
+ # Check for updates to GitHub Actions every weekday
8
+ interval: "daily"
@@ -13,10 +13,10 @@ jobs:
13
13
 
14
14
  strategy:
15
15
  matrix:
16
- ruby-version: ["3.0", "2.7", "2.6", "2.5", "jruby-head"]
16
+ ruby-version: [3.1, "3.0", 2.7, jruby-head]
17
17
 
18
18
  steps:
19
- - uses: actions/checkout@v2
19
+ - uses: actions/checkout@v3
20
20
  - name: Set up Ruby ${{ matrix.ruby-version }}
21
21
  uses: ruby/setup-ruby@v1
22
22
  with:
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ AllCops:
2
+ Exclude:
3
+ - "tmp/**/*"
4
+ inherit_gem:
5
+ barsoom_utils: shared_rubocop.yml
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## [7.0.0](https://github.com/barsoom/attr_extras/releases/tag/v7.0.0)
4
+
5
+ - Drop end-of-lifed Ruby 2.5 and 2.6.
6
+ - Don't share default value object instances. (We now do a shallow `dup`.) Thanks to [sammo1235](https://github.com/barsoom/attr_extras/pull/46)!
7
+
3
8
  ## [6.2.4](https://github.com/barsoom/attr_extras/releases/tag/v6.2.4)
4
9
 
5
10
  - Fix keyword argument warnings with Ruby 2.7. Thanks to [Elliot Winkler](https://github.com/barsoom/attr_extras/pull/34)!
data/Gemfile CHANGED
@@ -1,4 +1,12 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in attr_extras.gemspec
4
4
  gemspec
5
+
6
+ group :development, :test do
7
+ gem "barsoom_utils"
8
+ gem "m" # Running individual tests.
9
+ gem "minitest"
10
+ gem "rake"
11
+ gem "rubocop"
12
+ end
data/README.md CHANGED
@@ -517,17 +517,6 @@ You can run an individual test using the [m](https://github.com/qrush/m) gem:
517
517
  The tests are intentionally split into two test suites for reasons described in `Rakefile`.
518
518
 
519
519
 
520
- ## Contributors
521
-
522
- * [Henrik Nyh](https://github.com/henrik)
523
- * [Joakim Kolsjö](https://github.com/joakimk)
524
- * [Victor Arias](https://github.com/victorarias)
525
- * [Teo Ljungberg](https://github.com/teoljungberg)
526
- * [Kim Persson](https://github.com/lavinia)
527
- * [Joe Ferris](https://github.com/jferris)
528
- * [Julien Vanier](https://github.com/monkbroc)
529
-
530
-
531
520
  ## License
532
521
 
533
522
  [MIT](LICENSE.txt)
data/attr_extras.gemspec CHANGED
@@ -2,23 +2,17 @@
2
2
  require File.expand_path("../lib/attr_extras/version", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Henrik Nyh", "Joakim Kolsjö", "Tomas Skogberg", "Victor Arias", "Ola K"]
6
- gem.email = ["henrik@nyh.se"]
5
+ gem.authors = [ "Henrik Nyh", "Joakim Kolsjö", "Tomas Skogberg", "Victor Arias", "Ola K" ]
6
+ gem.email = [ "henrik@nyh.se" ]
7
7
  gem.summary = %q{Takes some boilerplate out of Ruby with methods like attr_initialize.}
8
8
  gem.homepage = "https://github.com/barsoom/attr_extras"
9
9
 
10
10
  gem.files = `git ls-files`.split($\)
11
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
11
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
12
12
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
13
  gem.name = "attr_extras"
14
- gem.require_paths = ["lib"]
14
+ gem.require_paths = [ "lib" ]
15
15
  gem.license = "MIT"
16
16
  gem.version = AttrExtras::VERSION
17
- gem.metadata = { "rubygems_mfa_required" => "true" }
18
-
19
- gem.add_development_dependency "minitest", ">= 5"
20
- gem.add_development_dependency "m", "~> 1.5.1" # Running individual tests.
21
-
22
- # For Travis CI.
23
- gem.add_development_dependency "rake"
17
+ gem.metadata = { "rubygems_mfa_required" => "true" }
24
18
  end
@@ -1,6 +1,7 @@
1
1
  class AttrExtras::AttrImplement
2
2
  def initialize(klass, names)
3
- @klass, @names = klass, names.dup
3
+ @klass = klass
4
+ @names = names.dup
4
5
  end
5
6
 
6
7
  def apply
@@ -2,7 +2,9 @@ require "attr_extras/params_builder"
2
2
 
3
3
  class AttrExtras::AttrInitialize
4
4
  def initialize(klass, names, block)
5
- @klass, @names, @block = klass, names, block
5
+ @klass = klass
6
+ @names = names
7
+ @block = block
6
8
  end
7
9
 
8
10
  attr_reader :klass, :names
@@ -19,13 +21,13 @@ class AttrExtras::AttrInitialize
19
21
  validate_args = method(:validate_args)
20
22
 
21
23
  klass.send(:define_method, :initialize) do |*values|
22
- hash_values = (values[(klass_params.positional_args.length)..-1] || []).inject(:merge) || {}
24
+ hash_values = (values[(klass_params.positional_args.length)..-1] || []).reduce(:merge) || {}
23
25
 
24
26
  validate_arity.call(values.length, self.class)
25
27
  validate_args.call(values, klass_params)
26
28
 
27
29
  klass_params.default_values.each do |name, default_value|
28
- instance_variable_set("@#{name}", default_value)
30
+ instance_variable_set("@#{name}", default_value.dup)
29
31
  end
30
32
 
31
33
  klass_params.positional_args.zip(values).each do |name, value|
@@ -55,7 +57,7 @@ class AttrExtras::AttrInitialize
55
57
  end
56
58
 
57
59
  def validate_args(values, klass_params)
58
- hash_values = values[(klass_params.positional_args.length)..-1].inject(:merge) || {}
60
+ hash_values = values[(klass_params.positional_args.length)..-1].reduce(:merge) || {}
59
61
  unknown_keys = hash_values.keys - klass_params.hash_args_names
60
62
 
61
63
  if unknown_keys.any?
@@ -1,6 +1,7 @@
1
1
  class AttrExtras::AttrValue
2
2
  def initialize(klass, *names)
3
- @klass, @names = klass, names
3
+ @klass = klass
4
+ @names = names
4
5
  end
5
6
 
6
7
  attr_reader :klass, :names
@@ -25,13 +25,13 @@ module AttrExtras
25
25
  end
26
26
 
27
27
  def hash_args_required
28
- @hash_args_required ||= hash_args.select { |name| name.to_s.end_with?(REQUIRED_SIGN) }.
29
- map { |name| remove_required_sign(name) }
28
+ @hash_args_required ||= hash_args.select { |name| name.to_s.end_with?(REQUIRED_SIGN) }
29
+ .map { |name| remove_required_sign(name) }
30
30
  end
31
31
 
32
32
  def default_values
33
33
  @default_values ||= begin
34
- default_values_hash = names.flatten.select { |name| name.is_a?(Hash) }.inject(:merge) || {}
34
+ default_values_hash = names.flatten.select { |name| name.is_a?(Hash) }.reduce(:merge) || {}
35
35
 
36
36
  default_values_hash.map { |name, value|
37
37
  [ remove_required_sign(name), value ]
@@ -1,7 +1,8 @@
1
1
  module AttrExtras::Utils
2
2
  def self.flat_names(names)
3
- names.flatten.
4
- flat_map { |x| x.is_a?(Hash) ? x.keys : x }.
5
- map { |x| x.to_s.sub(/!\z/, "") }
3
+ names
4
+ .flatten
5
+ .flat_map { |x| x.is_a?(Hash) ? x.keys : x }
6
+ .map { |x| x.to_s.sub(/!\z/, "") }
6
7
  end
7
8
  end
@@ -1,3 +1,3 @@
1
1
  module AttrExtras
2
- VERSION = "6.2.5"
2
+ VERSION = "7.0.0"
3
3
  end
@@ -65,4 +65,29 @@ describe Object, ".aattr_initialize" do
65
65
 
66
66
  _(example.foo).must_equal "Foo"
67
67
  end
68
+
69
+ it "does not use the same default value object across class instances" do
70
+ klass = Class.new do
71
+ aattr_initialize [:name, items: []]
72
+ end
73
+
74
+ data = [
75
+ { name: "One", items: [1, 2, 3] },
76
+ { name: "Two", items: [4, 5, 6] },
77
+ ]
78
+
79
+ results = data.each_with_object([]) do |datum, results|
80
+ name, items = datum.values_at(:name, :items)
81
+ foo = klass.new(name: name)
82
+
83
+ items.each do |n|
84
+ foo.items << n
85
+ end
86
+
87
+ results << foo
88
+ end
89
+
90
+ _(results.first.items).must_equal [1, 2, 3]
91
+ _(results.last.items).must_equal [4, 5, 6]
92
+ end
68
93
  end
@@ -13,7 +13,7 @@ describe Object, ".attr_implement" do
13
13
 
14
14
  it "allows specifying arity and argument names" do
15
15
  klass = Class.new do
16
- attr_implement :foo, [:name, :age]
16
+ attr_implement :foo, [ :name, :age ]
17
17
  end
18
18
 
19
19
  example = klass.new
@@ -80,7 +80,7 @@ end
80
80
  describe Object, ".cattr_implement" do
81
81
  it "applies to class methods" do
82
82
  klass = Class.new do
83
- cattr_implement :foo, [:name, :age]
83
+ cattr_implement :foo, [ :name, :age ]
84
84
  end
85
85
 
86
86
  exception = _(lambda { klass.foo(1, 2) }).must_raise AttrExtras::MethodNotImplementedError
@@ -24,7 +24,7 @@ describe Object, ".attr_initialize" do
24
24
 
25
25
  it "can set ivars from a hash" do
26
26
  klass = Class.new do
27
- attr_initialize :foo, [:bar, :baz]
27
+ attr_initialize :foo, [ :bar, :baz ]
28
28
  end
29
29
 
30
30
  example = klass.new("Foo", bar: "Bar", baz: "Baz")
@@ -35,7 +35,7 @@ describe Object, ".attr_initialize" do
35
35
 
36
36
  it "can set default values for keyword arguments" do
37
37
  klass = Class.new do
38
- attr_initialize :foo, [:bar, baz: "default baz"]
38
+ attr_initialize :foo, [ :bar, baz: "default baz" ]
39
39
  end
40
40
 
41
41
  example = klass.new("Foo", bar: "Bar")
@@ -49,7 +49,7 @@ describe Object, ".attr_initialize" do
49
49
 
50
50
  it "treats hash values as optional" do
51
51
  klass = Class.new do
52
- attr_initialize :foo, [:bar, :baz]
52
+ attr_initialize :foo, [ :bar, :baz ]
53
53
  end
54
54
 
55
55
  example = klass.new("Foo", bar: "Bar")
@@ -61,7 +61,7 @@ describe Object, ".attr_initialize" do
61
61
 
62
62
  it "can require hash values" do
63
63
  klass = Class.new do
64
- attr_initialize [:optional, :required!]
64
+ attr_initialize [ :optional, :required! ]
65
65
  end
66
66
 
67
67
  example = klass.new(required: "X")
@@ -72,7 +72,7 @@ describe Object, ".attr_initialize" do
72
72
 
73
73
  it "complains about unknown hash values" do
74
74
  klass = Class.new do
75
- attr_initialize :foo, [:bar, :baz!]
75
+ attr_initialize :foo, [ :bar, :baz! ]
76
76
  end
77
77
 
78
78
  # Should not raise.
@@ -85,7 +85,7 @@ describe Object, ".attr_initialize" do
85
85
  # Regression.
86
86
  it "assigns hash values to positional arguments even when there's also hash arguments" do
87
87
  klass = Class.new do
88
- attr_initialize :foo, [:bar]
88
+ attr_initialize :foo, [ :bar ]
89
89
  end
90
90
 
91
91
  # Should not raise.
@@ -95,7 +95,7 @@ describe Object, ".attr_initialize" do
95
95
  # Regression.
96
96
  it "only looks at hash arguments when determining missing required keys" do
97
97
  klass = Class.new do
98
- attr_initialize :foo, [:bar!]
98
+ attr_initialize :foo, [ :bar! ]
99
99
  end
100
100
 
101
101
  # Provides a hash to "foo" but does not provide "bar".
@@ -4,7 +4,7 @@ describe AttrExtras::AttrInitialize::ParamsBuilder do
4
4
  subject { AttrExtras::AttrInitialize::ParamsBuilder.new(names) }
5
5
 
6
6
  describe "when positional and hash params are present" do
7
- let(:names) { [ :foo, :bar, [ :baz, :qux!, quux: "Quux" ]] }
7
+ let(:names) { [ :foo, :bar, [ :baz, :qux!, quux: "Quux" ] ] }
8
8
 
9
9
  it "properly devides params by the type" do
10
10
  _(subject.positional_args).must_equal [ :foo, :bar ]
@@ -16,7 +16,7 @@ describe AttrExtras::AttrInitialize::ParamsBuilder do
16
16
  end
17
17
 
18
18
  describe "when only positional params are present" do
19
- let(:names) { [ :foo, :bar] }
19
+ let(:names) { [ :foo, :bar ] }
20
20
 
21
21
  it "properly devides params by the type" do
22
22
  _(subject.positional_args).must_equal [ :foo, :bar ]
@@ -28,7 +28,7 @@ describe AttrExtras::AttrInitialize::ParamsBuilder do
28
28
  end
29
29
 
30
30
  describe "when only hash params are present" do
31
- let(:names) { [[ { baz: "Baz" }, :qux!, { quux: "Quux" } ]] }
31
+ let(:names) { [ [ { baz: "Baz" }, :qux!, { quux: "Quux" } ] ] }
32
32
 
33
33
  it "properly devides params by the type" do
34
34
  _(subject.positional_args).must_be_empty
@@ -12,7 +12,7 @@ describe Object, ".pattr_initialize" do
12
12
 
13
13
  it "works with hash ivars" do
14
14
  klass = Class.new do
15
- pattr_initialize :foo, [:bar, :baz!]
15
+ pattr_initialize :foo, [ :bar, :baz! ]
16
16
  end
17
17
 
18
18
  example = klass.new("Foo", bar: "Bar", baz: "Baz")
@@ -13,7 +13,7 @@ describe AttrExtras::Utils do
13
13
  end
14
14
 
15
15
  it "flattens hash arguments with defaults and strips any bangs" do
16
- _(AttrExtras::Utils.flat_names([ :foo, [ bar: "Bar", baz!: "Baz"] ])).must_equal [ "foo", "bar", "baz" ]
16
+ _(AttrExtras::Utils.flat_names([ :foo, [ bar: "Bar", baz!: "Baz" ] ])).must_equal [ "foo", "bar", "baz" ]
17
17
  end
18
18
  end
19
19
  end
@@ -15,7 +15,7 @@ describe Object, ".vattr_initialize" do
15
15
 
16
16
  it "works with hash ivars" do
17
17
  klass = Class.new do
18
- vattr_initialize :foo, [:bar, :baz!]
18
+ vattr_initialize :foo, [ :bar, :baz! ]
19
19
  end
20
20
 
21
21
  example1 = klass.new("Foo", bar: "Bar", baz: "Baz")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attr_extras
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.2.5
4
+ version: 7.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrik Nyh
@@ -12,50 +12,8 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2021-11-19 00:00:00.000000000 Z
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
18
- name: minitest
19
- requirement: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: '5'
24
- type: :development
25
- prerelease: false
26
- version_requirements: !ruby/object:Gem::Requirement
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
30
- version: '5'
31
- - !ruby/object:Gem::Dependency
32
- name: m
33
- requirement: !ruby/object:Gem::Requirement
34
- requirements:
35
- - - "~>"
36
- - !ruby/object:Gem::Version
37
- version: 1.5.1
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- requirements:
42
- - - "~>"
43
- - !ruby/object:Gem::Version
44
- version: 1.5.1
45
- - !ruby/object:Gem::Dependency
46
- name: rake
47
- requirement: !ruby/object:Gem::Requirement
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- version: '0'
52
- type: :development
53
- prerelease: false
54
- version_requirements: !ruby/object:Gem::Requirement
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- version: '0'
15
+ date: 2022-11-10 00:00:00.000000000 Z
16
+ dependencies: []
59
17
  description:
60
18
  email:
61
19
  - henrik@nyh.se
@@ -63,8 +21,10 @@ executables: []
63
21
  extensions: []
64
22
  extra_rdoc_files: []
65
23
  files:
24
+ - ".github/dependabot.yml"
66
25
  - ".github/workflows/ci.yml"
67
26
  - ".gitignore"
27
+ - ".rubocop.yml"
68
28
  - CHANGELOG.md
69
29
  - Gemfile
70
30
  - LICENSE.txt
@@ -119,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
79
  - !ruby/object:Gem::Version
120
80
  version: '0'
121
81
  requirements: []
122
- rubygems_version: 3.2.28
82
+ rubygems_version: 3.3.20
123
83
  signing_key:
124
84
  specification_version: 4
125
85
  summary: Takes some boilerplate out of Ruby with methods like attr_initialize.