Skip to content

Commit b487e0d

Browse files
allow type keyword argument for arrays (#12)
1 parent e819ade commit b487e0d

9 files changed

+86
-51
lines changed

.github/workflows/test_and_lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
ruby-version: ['3.1', '3.0']
19+
ruby-version: ['3.2', '3.1', '3.0']
2020

2121
steps:
2222
- uses: actions/checkout@v2

.ruby-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.2
1+
3.2.2

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change log
22

3+
## v1.3.0
4+
5+
- Array attributes now allow a "type" keyword argument instead of a third positional argument
6+
37
## v1.2.0
48

59
- Added the `prefix` option to the `CopyErrorsValidator`

Gemfile

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# frozen_string_literal: true
22

33
source "https://rubygems.org"
4-
gem "citizens-advice-style", git: "https://github.com/citizensadvice/citizens-advice-style-ruby", tag: "v9.0.0"
4+
gem "citizens-advice-style", git: "https://github.com/citizensadvice/citizens-advice-style-ruby", tag: "v10.0.1"
5+
6+
group :development, :test do
7+
gem "debug"
8+
gem "rspec"
9+
gem "shoulda-matchers"
10+
end
511

612
gemspec

Gemfile.lock

+54-42
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,96 @@
11
GIT
22
remote: https://github.com/citizensadvice/citizens-advice-style-ruby
3-
revision: 1a0f7e2cdcfd455a1c4d757c03d1c45eb160551d
4-
tag: v9.0.0
3+
revision: ca09fc508ee68c238428d4558701a766f1e12c79
4+
tag: v10.0.1
55
specs:
6-
citizens-advice-style (9.0.0)
7-
rubocop (~> 1.30.1)
8-
rubocop-rspec (~> 2.11.1)
6+
citizens-advice-style (10.0.1)
7+
rubocop (~> 1.45)
8+
rubocop-rails (~> 2.17)
9+
rubocop-rspec (~> 2.18)
910

1011
PATH
1112
remote: .
1213
specs:
13-
strong_attributes (1.2.0)
14+
strong_attributes (1.3.0)
1415
activemodel (>= 6.1.0)
1516

1617
GEM
1718
remote: https://rubygems.org/
1819
specs:
19-
activemodel (7.0.3.1)
20-
activesupport (= 7.0.3.1)
21-
activesupport (7.0.3.1)
20+
activemodel (7.0.4.3)
21+
activesupport (= 7.0.4.3)
22+
activesupport (7.0.4.3)
2223
concurrent-ruby (~> 1.0, >= 1.0.2)
2324
i18n (>= 1.6, < 2)
2425
minitest (>= 5.1)
2526
tzinfo (~> 2.0)
2627
ast (2.4.2)
27-
concurrent-ruby (1.1.10)
28-
debug (1.6.2)
29-
irb (>= 1.3.6)
28+
concurrent-ruby (1.2.2)
29+
debug (1.7.2)
30+
irb (>= 1.5.0)
3031
reline (>= 0.3.1)
3132
diff-lcs (1.5.0)
3233
i18n (1.12.0)
3334
concurrent-ruby (~> 1.0)
34-
io-console (0.5.11)
35-
irb (1.4.1)
35+
io-console (0.6.0)
36+
irb (1.6.4)
3637
reline (>= 0.3.0)
37-
minitest (5.16.3)
38+
json (2.6.3)
39+
minitest (5.18.0)
3840
parallel (1.22.1)
39-
parser (3.1.2.1)
41+
parser (3.2.2.0)
4042
ast (~> 2.4.1)
43+
rack (3.0.7)
4144
rainbow (3.1.1)
42-
regexp_parser (2.5.0)
43-
reline (0.3.1)
45+
regexp_parser (2.8.0)
46+
reline (0.3.3)
4447
io-console (~> 0.5)
4548
rexml (3.2.5)
46-
rspec (3.11.0)
47-
rspec-core (~> 3.11.0)
48-
rspec-expectations (~> 3.11.0)
49-
rspec-mocks (~> 3.11.0)
50-
rspec-core (3.11.0)
51-
rspec-support (~> 3.11.0)
52-
rspec-expectations (3.11.0)
49+
rspec (3.12.0)
50+
rspec-core (~> 3.12.0)
51+
rspec-expectations (~> 3.12.0)
52+
rspec-mocks (~> 3.12.0)
53+
rspec-core (3.12.1)
54+
rspec-support (~> 3.12.0)
55+
rspec-expectations (3.12.2)
5356
diff-lcs (>= 1.2.0, < 2.0)
54-
rspec-support (~> 3.11.0)
55-
rspec-mocks (3.11.1)
57+
rspec-support (~> 3.12.0)
58+
rspec-mocks (3.12.5)
5659
diff-lcs (>= 1.2.0, < 2.0)
57-
rspec-support (~> 3.11.0)
58-
rspec-support (3.11.0)
59-
rubocop (1.30.1)
60+
rspec-support (~> 3.12.0)
61+
rspec-support (3.12.0)
62+
rubocop (1.50.2)
63+
json (~> 2.3)
6064
parallel (~> 1.10)
61-
parser (>= 3.1.0.0)
65+
parser (>= 3.2.0.0)
6266
rainbow (>= 2.2.2, < 4.0)
6367
regexp_parser (>= 1.8, < 3.0)
6468
rexml (>= 3.2.5, < 4.0)
65-
rubocop-ast (>= 1.18.0, < 2.0)
69+
rubocop-ast (>= 1.28.0, < 2.0)
6670
ruby-progressbar (~> 1.7)
67-
unicode-display_width (>= 1.4.0, < 3.0)
68-
rubocop-ast (1.21.0)
69-
parser (>= 3.1.1.0)
70-
rubocop-rspec (2.11.1)
71-
rubocop (~> 1.19)
72-
ruby-progressbar (1.11.0)
73-
shoulda-matchers (5.1.0)
71+
unicode-display_width (>= 2.4.0, < 3.0)
72+
rubocop-ast (1.28.0)
73+
parser (>= 3.2.1.0)
74+
rubocop-capybara (2.17.1)
75+
rubocop (~> 1.41)
76+
rubocop-rails (2.19.1)
77+
activesupport (>= 4.2.0)
78+
rack (>= 1.1)
79+
rubocop (>= 1.33.0, < 2.0)
80+
rubocop-rspec (2.20.0)
81+
rubocop (~> 1.33)
82+
rubocop-capybara (~> 2.17)
83+
ruby-progressbar (1.13.0)
84+
shoulda-matchers (5.3.0)
7485
activesupport (>= 5.2.0)
75-
tzinfo (2.0.5)
86+
tzinfo (2.0.6)
7687
concurrent-ruby (~> 1.0)
77-
unicode-display_width (2.2.0)
88+
unicode-display_width (2.4.2)
7889

7990
PLATFORMS
8091
x86_64-darwin-20
8192
x86_64-darwin-21
93+
x86_64-darwin-22
8294
x86_64-linux
8395

8496
DEPENDENCIES
@@ -89,4 +101,4 @@ DEPENDENCIES
89101
strong_attributes!
90102

91103
BUNDLED WITH
92-
2.3.3
104+
2.4.12

lib/strong_attributes.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def attribute(name, type = ActiveModel::Type::Value.new, subtype = nil, **option
3535
self._attribute_default_procs = _attribute_default_procs.merge(name => options.delete(:default))
3636
end
3737
if type == :array
38-
super(name, Type::Array.new(type: subtype), **options)
38+
super(name, Type::Array.new(type: subtype || options.delete(:type)), **options)
3939
else
4040
super(name, type, **options)
4141
end

lib/strong_attributes/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module StrongAttributes
4-
VERSION = "1.2.0"
4+
VERSION = "1.3.0"
55
end

spec/strong_attributes_spec.rb

+17
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,23 @@
119119
end
120120
end
121121

122+
context "when defined with :array and type keyword argument" do
123+
let(:test_class) do
124+
Class.new do
125+
include StrongAttributes
126+
attribute :name, :array, type: ActiveModel::Type::String.new
127+
end
128+
end
129+
130+
it "creates an attribute that converts items to an array" do
131+
expect(test_class.new(name: "foo").name).to eq ["foo"]
132+
end
133+
134+
it "creates an attribute that saves items as an array" do
135+
expect(test_class.new(name: %w[foo bar]).name).to eq %w[foo bar]
136+
end
137+
end
138+
122139
context "when modified in place" do
123140
let(:test_class) do
124141
Class.new do

strong_attributes.gemspec

-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,4 @@ Gem::Specification.new do |s|
1414
s.metadata["rubygems_mfa_required"] = "true"
1515

1616
s.add_runtime_dependency "activemodel", ">= 6.1.0"
17-
18-
s.add_development_dependency "debug"
19-
s.add_development_dependency "rspec"
20-
s.add_development_dependency "shoulda-matchers"
2117
end

0 commit comments

Comments
 (0)