immutable-struct 2.4.1 → 2.5.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e0ef4c872306eeb408eaaee1d514de56f0917cbb5ab32a721279feb6e4ed1971
4
- data.tar.gz: 5c1afb5b32cb4edf20ec71ad760927ac376c582826eb4a96d276860cf4710efa
3
+ metadata.gz: c06154021767382ddac96df4c5f0291ef6fe0b4492b835fc36295b700fed19b7
4
+ data.tar.gz: d05c85009279d86f545e9b0d07645a4680e88b45d149feb196419cdab3f7b6a2
5
5
  SHA512:
6
- metadata.gz: f4c5c9f24d9650b8c42bd57d9266973540ffce2990aae6b7407e95a3fd2dc9e533d943fe4eaf357c40dc9bb2c1598bd59d054571a0a42de0a70bc9b791e0ac03
7
- data.tar.gz: 8512b6b471c543b5379224ca029c529ee0550f889d27b0986e3bc26e6ea45ec03932cc1d41bc2178e288d53baafdcc1e1e8f7a732e5cd6c035c59863c408b0ea
6
+ metadata.gz: 1f636be7f8e287d9573a7d1df9ca1af2dee7cdc3aae4f5ec6295541e68b30d7e99efac0b9b6dd870f29888baf4f45515148e422f3617c8668b3ef18515253190
7
+ data.tar.gz: c35f53b3f63f6f3b493223041a986f37c7050b5f1eff441172d974a7bb026db42581b8131424c5458067562774bb2db768018698bc89afb922b9d226fd700be6
data/.circleci/config.yml CHANGED
@@ -1,15 +1,81 @@
1
- # DO NOT MODIFY - this is managed by Git Reduce in goro
1
+ # DO NOT MODIFY - this is managed by Git Reduce in goro and generated from build-matrix.json
2
2
  #
3
3
  ---
4
- version: 2
4
+ version: 2.1
5
+
6
+ ############
7
+ ## Github Actions Pipeline Params
8
+ ############
9
+
10
+ parameters:
11
+ GHA_Event:
12
+ type: string
13
+ default: ""
14
+ GHA_Actor:
15
+ type: string
16
+ default: ""
17
+ GHA_Action:
18
+ type: string
19
+ default: ""
20
+ GHA_Meta:
21
+ type: string
22
+ default: ""
23
+
5
24
  jobs:
6
- ruby-2.6.1:
25
+ generate-and-push-docs:
7
26
  docker:
8
- - image: circleci/ruby:2.6.1
27
+ - image: cimg/ruby:3.3.7
28
+ auth:
29
+ username: "$DOCKERHUB_USERNAME"
30
+ password: "$DOCKERHUB_PASSWORD"
31
+ steps:
32
+ - checkout
33
+ - run: bundle config stitchfix01.jfrog.io $ARTIFACTORY_USER:$ARTIFACTORY_TOKEN
34
+ - run: bundle install
35
+ - run:
36
+ name: Generate documentation
37
+ command: ' if [[ $(bundle exec rake -T docs:generate:custom) ]]; then echo
38
+ "Generating docs using rake task docs:generate:custom" ; bundle exec rake
39
+ docs:generate:custom ; elif [[ $(bundle exec rake -T docs:generate) ]];
40
+ then echo "Generating docs using rake task docs:generate" ; bundle exec
41
+ rake docs:generate ; else echo "Skipping doc generation" ; exit 0 ; fi '
42
+ - run:
43
+ name: Push documentation to Unwritten
44
+ command: if [[ $(bundle exec rake -T docs:push) ]]; then bundle exec rake
45
+ docs:push; fi
46
+ release:
47
+ docker:
48
+ - image: cimg/ruby:3.3.7
49
+ auth:
50
+ username: "$DOCKERHUB_USERNAME"
51
+ password: "$DOCKERHUB_PASSWORD"
52
+ steps:
53
+ - checkout
54
+ - run: bundle config stitchfix01.jfrog.io $ARTIFACTORY_USER:$ARTIFACTORY_TOKEN
55
+ - run: bundle install
56
+ - run:
57
+ name: Artifactory login
58
+ command: mkdir -p ~/.gem && curl -u$ARTIFACTORY_USER:$ARTIFACTORY_TOKEN https://stitchfix01.jfrog.io/stitchfix01/api/gems/eng-gems/api/v1/api_key.yaml
59
+ > ~/.gem/credentials && chmod 0600 ~/.gem/credentials
60
+ - run:
61
+ name: Build/release gem to artifactory
62
+ command: bundle exec rake push_artifactory
63
+ ruby-3_3_7:
64
+ docker:
65
+ - image: cimg/ruby:3.3.7
66
+ auth:
67
+ username: "$DOCKERHUB_USERNAME"
68
+ password: "$DOCKERHUB_PASSWORD"
9
69
  working_directory: "~/immutable-struct"
10
70
  steps:
11
71
  - checkout
12
- - run: bundle install --full-index
72
+ - run:
73
+ name: Check for Gemfile.lock presence
74
+ command: ' if (test -f Gemfile.lock) then echo "Dont commit Gemfile.lock (see
75
+ https://github.com/stitchfix/eng-wiki/blob/main/architecture-decisions/0009-rubygem-dependencies-will-be-managed-more-explicitly.md)"
76
+ 1>&2 ; exit 1 ; else exit 0 ; fi '
77
+ - run: bundle config stitchfix01.jfrog.io $ARTIFACTORY_USER:$ARTIFACTORY_TOKEN
78
+ - run: bundle install
13
79
  - run: bundle exec rspec --format RspecJunitFormatter --out /tmp/test-results/rspec.xml
14
80
  --format=doc
15
81
  - run:
@@ -18,17 +84,26 @@ jobs:
18
84
  fi
19
85
  - run:
20
86
  name: Notify Pager Duty
21
- command: 'bundle exec y-notify #eng-platform'
87
+ command: bundle exec y-notify "#app-platform-ops"
22
88
  when: on_fail
23
89
  - store_test_results:
24
90
  path: "/tmp/test-results"
25
- ruby-2.5.3:
91
+ ruby-3_2_7:
26
92
  docker:
27
- - image: circleci/ruby:2.5.3
93
+ - image: cimg/ruby:3.2.7
94
+ auth:
95
+ username: "$DOCKERHUB_USERNAME"
96
+ password: "$DOCKERHUB_PASSWORD"
28
97
  working_directory: "~/immutable-struct"
29
98
  steps:
30
99
  - checkout
31
- - run: bundle install --full-index
100
+ - run:
101
+ name: Check for Gemfile.lock presence
102
+ command: ' if (test -f Gemfile.lock) then echo "Dont commit Gemfile.lock (see
103
+ https://github.com/stitchfix/eng-wiki/blob/main/architecture-decisions/0009-rubygem-dependencies-will-be-managed-more-explicitly.md)"
104
+ 1>&2 ; exit 1 ; else exit 0 ; fi '
105
+ - run: bundle config stitchfix01.jfrog.io $ARTIFACTORY_USER:$ARTIFACTORY_TOKEN
106
+ - run: bundle install
32
107
  - run: bundle exec rspec --format RspecJunitFormatter --out /tmp/test-results/rspec.xml
33
108
  --format=doc
34
109
  - run:
@@ -37,28 +112,50 @@ jobs:
37
112
  fi
38
113
  - run:
39
114
  name: Notify Pager Duty
40
- command: 'bundle exec y-notify #eng-platform'
115
+ command: bundle exec y-notify "#app-platform-ops"
41
116
  when: on_fail
42
117
  - store_test_results:
43
118
  path: "/tmp/test-results"
44
119
  workflows:
45
120
  version: 2
46
121
  on-commit:
122
+ unless:
123
+ equal: [ "schedule", << pipeline.parameters.GHA_Event >> ]
47
124
  jobs:
48
- - ruby-2.6.1:
125
+ - release:
49
126
  context: org-global
50
- - ruby-2.5.3:
127
+ requires:
128
+ - ruby-3_3_7
129
+ - ruby-3_2_7
130
+ filters:
131
+ tags:
132
+ only: "/^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:(-|\\.)(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$/"
133
+ branches:
134
+ ignore: /.*/
135
+ - generate-and-push-docs:
51
136
  context: org-global
52
- scheduled:
53
- triggers:
54
- - schedule:
55
- cron: 4 21 * * 1,2,3,4,5
137
+ requires:
138
+ - release
56
139
  filters:
140
+ tags:
141
+ only: "/^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:(-|\\.)(?:0|[1-9]\\d*|\\d*[a-zA-Z-][0-9a-zA-Z-]*))?(?:\\+([0-9a-zA-Z-]+(?:\\.[0-9a-zA-Z-]+)*))?$/"
57
142
  branches:
58
- only:
59
- - master
143
+ ignore: /.*/
144
+ - ruby-3_3_7:
145
+ context: org-global
146
+ filters:
147
+ tags:
148
+ only: &1 /.*/
149
+ - ruby-3_2_7:
150
+ context: org-global
151
+ filters:
152
+ tags:
153
+ only: *1
154
+ scheduled:
155
+ when:
156
+ equal: [ "schedule", << pipeline.parameters.GHA_Event >> ]
60
157
  jobs:
61
- - ruby-2.6.1:
158
+ - ruby-3_3_7:
62
159
  context: org-global
63
- - ruby-2.5.3:
160
+ - ruby-3_2_7:
64
161
  context: org-global
@@ -0,0 +1,11 @@
1
+ # THIS FILE IS NOT THE SOURCE OF TRUTH for app ownership. If this app
2
+ # is transferred to another team, the app ownership should be changed
3
+ # in fixops.
4
+ #
5
+ # View current canonical app ownership on Unwritten:
6
+ # https://unwritten.stitchfix.com/docs/applications-and-services
7
+ #
8
+ # This file uses the GitHub CODEOWNERS convention to assign PR reviewers:
9
+ # https://help.github.com/articles/about-codeowners/
10
+
11
+ * @stitchfix/app-platform
@@ -0,0 +1,7 @@
1
+ ## Problem
2
+
3
+ «Brief overview of the problem»
4
+
5
+ ## Solution
6
+
7
+ «Brief description of how you solved the problem»
@@ -0,0 +1,14 @@
1
+ on:
2
+ schedule:
3
+ - cron: '4 21 * * 1,2,3,4,5'
4
+ workflow_dispatch:
5
+
6
+ jobs:
7
+ trigger-circleci:
8
+ runs-on: ubuntu-latest
9
+ steps:
10
+ - name: CircleCI trigger on schedule
11
+ id: step1
12
+ uses: CircleCI-Public/trigger-circleci-pipeline-action@v1.0.5
13
+ env:
14
+ CCI_TOKEN: ${{ secrets.CCI_TOKEN || secrets.CCI_TOKEN_FOR_PUBLIC_REPOS }}
data/.gitignore CHANGED
@@ -11,6 +11,7 @@ lib/bundler/man
11
11
  pkg
12
12
  rdoc
13
13
  spec/reports
14
+ spec/examples.txt
14
15
  test/tmp
15
16
  test/version_tmp
16
17
  tmp
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.5.3
1
+ ruby-3.2.7
data/.travis.yml CHANGED
@@ -1,8 +1,10 @@
1
1
  language: ruby
2
- before_install:
3
- - gem install bundler
4
2
  rvm:
5
- - 2.5.0
6
- - 2.4.3
7
- - 2.3.6
3
+ - 2.6
4
+ - 2.7
8
5
  - ruby-head
6
+ before_install:
7
+ - gem install bundler
8
+ jobs:
9
+ allow_failures:
10
+ - rvm: ruby-head
data/build-matrix.json CHANGED
@@ -1,4 +1,3 @@
1
1
  {
2
- "build_matrix": {
3
- }
2
+ "build_matrix": {}
4
3
  }
@@ -6,7 +6,7 @@
6
6
  # will be evaluated as if it were inside a class definition, allowing you
7
7
  # to add methods, include or extend modules, or do whatever else you want.
8
8
  class ImmutableStruct
9
- VERSION='2.4.1' #:nodoc:
9
+ VERSION='2.5.0' #:nodoc:
10
10
  # Create a new class with the given read-only attributes.
11
11
  #
12
12
  # attributes:: list of symbols or strings that can be used to create attributes.
@@ -121,6 +121,14 @@ class ImmutableStruct
121
121
  end
122
122
  (attribute_values + [self.class]).hash
123
123
  end
124
+
125
+ def deconstruct_keys(keys)
126
+ if keys
127
+ to_h.slice(*keys)
128
+ else
129
+ to_h
130
+ end
131
+ end
124
132
  end
125
133
  klass.class_exec(&block) unless block.nil?
126
134
 
data/owners.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "owners": [
3
3
  {
4
- "team": "platform"
4
+ "team": "dev-platform"
5
5
  }
6
6
  ]
7
7
  }
@@ -1,5 +1,6 @@
1
1
  require 'spec_helper.rb'
2
2
  require 'json'
3
+ require 'set'
3
4
 
4
5
  module TestModule
5
6
  def hello; "hello"; end
@@ -189,6 +190,46 @@ describe ImmutableStruct do
189
190
  end
190
191
  end
191
192
 
193
+ describe "#deconstruct_keys" do
194
+ it "returns a hash with the specified keys" do
195
+ klass = ImmutableStruct.new(:a, :b, :c)
196
+ instance = klass.new(a: 1, b: 2, c: 3)
197
+ expect(instance.deconstruct_keys([:a, :c])).to eq({ a: 1, c: 3 })
198
+ end
199
+
200
+ context "when keys are specified that do not exist in the struct" do
201
+ it 'returns only the keys that do exist' do
202
+ klass = ImmutableStruct.new(:a, :b, :c)
203
+ instance = klass.new(a: 1, b: 2, c: 3)
204
+ expect(instance.deconstruct_keys([:a, :foo])).to eq({ a: 1 })
205
+ end
206
+ end
207
+
208
+ it "allows an instance to be used with pattern matching" do
209
+ klass = ImmutableStruct.new(:a, :b, :c)
210
+ instance = klass.new(a: 1, b: 2, c: 3)
211
+ expect {
212
+ case instance
213
+ in { a: 1 }
214
+ # good!
215
+ end
216
+ # a NoMatchingPatternError would be raised if the pattern didn't match
217
+ }.not_to raise_error
218
+ end
219
+
220
+ context "pattern matching against 'any key'" do
221
+ it 'returns all properties' do
222
+ klass = ImmutableStruct.new(:a, :b, :c)
223
+ instance = klass.new(a: 1, b: 2, c: 3)
224
+ case instance
225
+ in **rest
226
+ expect(rest).to eq({ a: 1, b: 2, c: 3 })
227
+ end
228
+ # a NoMatchingPatternError would be raised if the pattern didn't match
229
+ end
230
+ end
231
+ end
232
+
192
233
  describe "merge" do
193
234
  it "returns a new object as a result of merging attributes" do
194
235
  klass = ImmutableStruct.new(:food, :snacks, :butter)
data/spec/spec_helper.rb CHANGED
@@ -7,5 +7,13 @@ RSpec.configure do |config|
7
7
  config.expect_with :rspec do |c|
8
8
  c.syntax = [:expect]
9
9
  end
10
- config.order = "random"
10
+
11
+ config.mock_with :rspec do |mocks|
12
+ mocks.verify_partial_doubles = true
13
+ end
14
+
15
+ config.order = :random
16
+ Kernel.srand config.seed
17
+
18
+ config.example_status_persistence_file_path = "spec/examples.txt"
11
19
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immutable-struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stitch Fix Engineering
8
8
  - Dave Copeland
9
9
  - Simeon Willbanks
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-04-18 00:00:00.000000000 Z
13
+ date: 2025-02-25 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
@@ -79,6 +79,9 @@ extensions: []
79
79
  extra_rdoc_files: []
80
80
  files:
81
81
  - ".circleci/config.yml"
82
+ - ".github/CODEOWNERS"
83
+ - ".github/PULL_REQUEST_TEMPLATE.md"
84
+ - ".github/workflows/scheduled_cci.yml"
82
85
  - ".gitignore"
83
86
  - ".ruby-gemset"
84
87
  - ".ruby-version"
@@ -99,7 +102,7 @@ homepage: https://github.com/stitchfix/immutable-struct
99
102
  licenses:
100
103
  - MIT
101
104
  metadata: {}
102
- post_install_message:
105
+ post_install_message:
103
106
  rdoc_options: []
104
107
  require_paths:
105
108
  - lib
@@ -114,8 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
117
  - !ruby/object:Gem::Version
115
118
  version: '0'
116
119
  requirements: []
117
- rubygems_version: 3.0.1
118
- signing_key:
120
+ rubygems_version: 3.5.11
121
+ signing_key:
119
122
  specification_version: 4
120
123
  summary: Easily create value objects without the pain of Ruby's Struct (or its setters)
121
124
  test_files: