static_collection 0.3.2 → 0.4.1

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: 98017f3d39c6af6afaaaeb5ddd30dc586c09c9a5a1ad3ccb5c894e123959947c
4
- data.tar.gz: df0fbf27a32cde5538df55003b59f9320926ffbe0e323e050e52ce3f09b9ba4c
3
+ metadata.gz: b9aa4c2914ed7e5afa37b77be9b321e6a48a6ef0810562558570aac0c35dc10f
4
+ data.tar.gz: acab38148246d6754fec822de533ca28cfc3cd3cac926654fbd0fec5f1c8254b
5
5
  SHA512:
6
- metadata.gz: 531a720c36212eae51f9319ae20802d868c68ebc5a9f4345017cf04f2f8eb98b2496f552301793efdb51a5500512b2dac3064f81ce6034673722497715ae2bc0
7
- data.tar.gz: 6b389bb60c43c02215583508ddf1e08037b8971674a996bfbe9b8c1f3addfd45d536aa05b79a1a3eefcadc744a8ececa9a2864333a826b03eb3b9052115b868e
6
+ metadata.gz: 64aa40d46ea3499b4e3e7a62f916ca945c906f65f5e613130d6e6dfb5ee03bfad12399ef6a02fd0ae74fe67a5a06719f9ecbbb55e936f2b89af10018a53c672f
7
+ data.tar.gz: 411577479aed3cf9ab808ba0c29c02545ce8ace7faefd563f59dff89ece347e86223daeb73a22bd7d60798aced033f5a970d929ef6a50ac4be06ea0ca9ced78c
data/.github/CODEOWNERS CHANGED
@@ -1 +1 @@
1
- * @wealthsimple/developer-tools
1
+ * @wealthsimple/backend-platform
@@ -0,0 +1,15 @@
1
+ ---
2
+ name: Default
3
+
4
+ on:
5
+ push:
6
+
7
+ concurrency:
8
+ group: ${{ github.workflow }}-${{ github.ref }}
9
+ cancel-in-progress: true
10
+
11
+ jobs:
12
+ build_and_publish:
13
+ name: Build and Publish
14
+ uses: wealthsimple/public-github-workflows/.github/workflows/ruby-gem-build.yaml@main
15
+ secrets: inherit
data/CHANGELOG.md ADDED
@@ -0,0 +1,16 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## Unreleased
8
+
9
+ ## 0.4.1 - 2024-01-23
10
+ ### Changed
11
+ - Updated dependencies
12
+
13
+ ## 0.4.0 - 2024-01-23
14
+ ### Changed
15
+ - All Static Collections will consist of frozen objects
16
+ - Reduce initialization of objects
data/Gemfile.lock CHANGED
@@ -1,79 +1,116 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- static_collection (0.3.2)
4
+ static_collection (0.4.1)
5
5
  activesupport (>= 4)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (7.0.4.3)
10
+ activesupport (7.1.3)
11
+ base64
12
+ bigdecimal
11
13
  concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ connection_pool (>= 2.2.5)
15
+ drb
12
16
  i18n (>= 1.6, < 2)
13
17
  minitest (>= 5.1)
18
+ mutex_m
14
19
  tzinfo (~> 2.0)
20
+ addressable (2.8.6)
21
+ public_suffix (>= 2.0.2, < 6.0)
15
22
  ast (2.4.2)
16
- concurrent-ruby (1.2.2)
23
+ base64 (0.2.0)
24
+ bigdecimal (3.1.6)
25
+ concurrent-ruby (1.2.3)
26
+ connection_pool (2.4.1)
17
27
  diff-lcs (1.5.0)
18
- i18n (1.12.0)
28
+ drb (2.2.0)
29
+ ruby2_keywords
30
+ git (2.1.1)
31
+ activesupport (>= 5.0)
32
+ addressable (~> 2.8)
33
+ process_executer (~> 1.1)
34
+ rchardet (~> 1.8)
35
+ i18n (1.14.1)
19
36
  concurrent-ruby (~> 1.0)
20
- json (2.6.3)
21
- minitest (5.18.0)
22
- parallel (1.22.1)
23
- parser (3.2.0.0)
37
+ json (2.7.1)
38
+ language_server-protocol (3.17.0.3)
39
+ minitest (5.21.2)
40
+ mutex_m (0.2.0)
41
+ parallel (1.24.0)
42
+ parse_a_changelog (1.3.0)
43
+ treetop (~> 1.6)
44
+ parser (3.3.0.4)
24
45
  ast (~> 2.4.1)
25
- rack (3.0.7)
46
+ racc
47
+ polyglot (0.3.5)
48
+ process_executer (1.1.0)
49
+ public_suffix (5.1.1)
50
+ racc (1.7.3)
51
+ rack (3.0.9.1)
26
52
  rainbow (3.1.1)
27
- rake (13.0.6)
28
- regexp_parser (2.6.2)
29
- rexml (3.2.5)
53
+ rake (13.1.0)
54
+ rchardet (1.8.0)
55
+ regexp_parser (2.9.0)
56
+ rexml (3.2.8)
57
+ strscan (>= 3.0.9)
30
58
  rspec (3.12.0)
31
59
  rspec-core (~> 3.12.0)
32
60
  rspec-expectations (~> 3.12.0)
33
61
  rspec-mocks (~> 3.12.0)
34
- rspec-core (3.12.0)
62
+ rspec-core (3.12.2)
35
63
  rspec-support (~> 3.12.0)
36
- rspec-expectations (3.12.2)
64
+ rspec-expectations (3.12.3)
37
65
  diff-lcs (>= 1.2.0, < 2.0)
38
66
  rspec-support (~> 3.12.0)
39
67
  rspec-its (1.3.0)
40
68
  rspec-core (>= 3.0.0)
41
69
  rspec-expectations (>= 3.0.0)
42
- rspec-mocks (3.12.3)
70
+ rspec-mocks (3.12.6)
43
71
  diff-lcs (>= 1.2.0, < 2.0)
44
72
  rspec-support (~> 3.12.0)
45
- rspec-support (3.12.0)
46
- rubocop (1.44.1)
73
+ rspec-support (3.12.1)
74
+ rubocop (1.60.1)
47
75
  json (~> 2.3)
76
+ language_server-protocol (>= 3.17.0)
48
77
  parallel (~> 1.10)
49
- parser (>= 3.2.0.0)
78
+ parser (>= 3.3.0.2)
50
79
  rainbow (>= 2.2.2, < 4.0)
51
80
  regexp_parser (>= 1.8, < 3.0)
52
81
  rexml (>= 3.2.5, < 4.0)
53
- rubocop-ast (>= 1.24.1, < 2.0)
82
+ rubocop-ast (>= 1.30.0, < 2.0)
54
83
  ruby-progressbar (~> 1.7)
55
84
  unicode-display_width (>= 2.4.0, < 3.0)
56
- rubocop-ast (1.24.1)
57
- parser (>= 3.1.1.0)
58
- rubocop-capybara (2.17.0)
85
+ rubocop-ast (1.30.0)
86
+ parser (>= 3.2.1.0)
87
+ rubocop-capybara (2.20.0)
59
88
  rubocop (~> 1.41)
60
- rubocop-performance (1.15.2)
61
- rubocop (>= 1.7.0, < 2.0)
62
- rubocop-ast (>= 0.4.0)
63
- rubocop-rails (2.17.4)
89
+ rubocop-factory_bot (2.25.1)
90
+ rubocop (~> 1.41)
91
+ rubocop-performance (1.20.2)
92
+ rubocop (>= 1.48.1, < 2.0)
93
+ rubocop-ast (>= 1.30.0, < 2.0)
94
+ rubocop-rails (2.23.1)
64
95
  activesupport (>= 4.2.0)
65
96
  rack (>= 1.1)
66
97
  rubocop (>= 1.33.0, < 2.0)
67
- rubocop-rspec (2.18.1)
68
- rubocop (~> 1.33)
98
+ rubocop-ast (>= 1.30.0, < 2.0)
99
+ rubocop-rspec (2.26.1)
100
+ rubocop (~> 1.40)
69
101
  rubocop-capybara (~> 2.17)
70
- rubocop-vendor (0.8.10)
71
- rubocop (>= 0.53.0)
72
- ruby-progressbar (1.11.0)
102
+ rubocop-factory_bot (~> 2.22)
103
+ rubocop-vendor (0.13.0)
104
+ rubocop
105
+ ruby-progressbar (1.13.0)
106
+ ruby2_keywords (0.0.5)
107
+ strscan (3.1.0)
108
+ treetop (1.6.12)
109
+ polyglot (~> 0.3)
73
110
  tzinfo (2.0.6)
74
111
  concurrent-ruby (~> 1.0)
75
- unicode-display_width (2.4.2)
76
- ws-style (6.14.4)
112
+ unicode-display_width (2.5.0)
113
+ ws-style (6.14.7)
77
114
  rubocop (>= 1.36)
78
115
  rubocop-performance (>= 1.10.2)
79
116
  rubocop-rails (>= 2.9.1)
@@ -85,6 +122,8 @@ PLATFORMS
85
122
 
86
123
  DEPENDENCIES
87
124
  bundler (~> 2.0)
125
+ git
126
+ parse_a_changelog
88
127
  rake (~> 13.0)
89
128
  rspec (~> 3.0)
90
129
  rspec-its (~> 1.2)
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # static_collection
2
- [![GitHub Actions Badge](https://github.com/wealthsimple/static_collection/actions/workflows/main.yml/badge.svg)](https://github.com/wealthsimple/static_collection/actions)
2
+ [![GitHub Actions Badge](https://github.com/wealthsimple/static_collection/actions/workflows/default.yml/badge.svg)](https://github.com/wealthsimple/static_collection/actions)
3
3
 
4
4
  Rubygem for running basic queries against static data.
5
5
 
data/Rakefile CHANGED
@@ -1,6 +1,14 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'bundler/gem_tasks'
8
+ require 'rspec/core/rake_task'
9
+ require 'rubocop/rake_task'
3
10
 
4
11
  RSpec::Core::RakeTask.new(:spec)
12
+ RuboCop::RakeTask.new
5
13
 
6
- task default: :spec
14
+ task default: %i[spec rubocop]
@@ -1,3 +1,3 @@
1
1
  module StaticCollection
2
- VERSION = "0.3.2".freeze
2
+ VERSION = "0.4.1".freeze
3
3
  end
@@ -3,23 +3,27 @@ require "static_collection/version"
3
3
 
4
4
  module StaticCollection
5
5
  class Base
6
+ # rubocop:disable Metrics/MethodLength
6
7
  def self.set_source(source, defaults: {})
7
8
  raise "Source must be an array" unless source.is_a?(Array)
8
9
 
9
- instance_variable_set(:@defaults, defaults.stringify_keys)
10
- instance_variable_set(:@source, source.map(&:stringify_keys))
11
- raise "Source must have at least one value" unless count > 0
10
+ defaults = defaults.stringify_keys
11
+ raise "Source must have at least one value" if source.count <= 0
12
12
 
13
- all.first.attributes.each do |attribute_name, attribute_value|
13
+ values = source.map(&:stringify_keys).map { |s| new(deep_freeze(defaults.merge(s))) }
14
+ instance_variable_set(:@all, values)
15
+
16
+ all_attribute_names = values.flat_map { |v| v.attributes.keys }.uniq
17
+ all_attribute_names.each do |attribute_name|
14
18
  # Class methods
15
- define_singleton_method("find_by_#{attribute_name}") do |value|
19
+ define_singleton_method(:"find_by_#{attribute_name}") do |value|
16
20
  ActiveSupport::Deprecation.warn(
17
21
  "find_by_#{attribute_name} is deprecated for StaticCollection, " \
18
22
  "use find_by(#{attribute_name}: [value])",
19
23
  )
20
24
  all.find { |instance| instance.send(attribute_name) == value }
21
25
  end
22
- define_singleton_method("find_all_by_#{attribute_name}") do |value|
26
+ define_singleton_method(:"find_all_by_#{attribute_name}") do |value|
23
27
  ActiveSupport::Deprecation.warn(
24
28
  "find_all_by_#{attribute_name} is deprecated for StaticCollection, " \
25
29
  "use where(#{attribute_name}: [value])",
@@ -29,13 +33,33 @@ module StaticCollection
29
33
 
30
34
  # Instance methods
31
35
  send(:define_method, attribute_name) { attributes[attribute_name] }
32
- next unless attribute_value.is_a?(TrueClass) || attribute_value.is_a?(FalseClass)
33
-
34
36
  send(:define_method, "#{attribute_name}?") {
35
- attributes[attribute_name]
37
+ attributes[attribute_name] if attributes.key?(attribute_name)
36
38
  }
37
39
  end
38
40
  end
41
+ # rubocop:enable Metrics/MethodLength
42
+
43
+ class << self
44
+ private
45
+
46
+ def deep_freeze(obj)
47
+ case obj
48
+ when Hash
49
+ obj.each_with_object({}) do |(key, value), acc|
50
+ acc[deep_freeze(key)] = deep_freeze(value)
51
+ end.freeze
52
+ when Array
53
+ obj.map do |value|
54
+ deep_freeze(value)
55
+ end.freeze
56
+ when Symbol, Integer, NilClass
57
+ obj
58
+ else
59
+ obj.freeze
60
+ end
61
+ end
62
+ end
39
63
 
40
64
  def self.find_by(opts)
41
65
  all.find { |instance| opts.all? { |k, v| instance.send(k) == v } }
@@ -46,8 +70,7 @@ module StaticCollection
46
70
  end
47
71
 
48
72
  def self.all
49
- defaults = instance_variable_get(:@defaults)
50
- instance_variable_get(:@source).map { |s| new(defaults.merge(s)) }
73
+ instance_variable_get(:@all)
51
74
  end
52
75
 
53
76
  def self.count
@@ -25,6 +25,8 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency "activesupport", ">= 4"
26
26
 
27
27
  spec.add_development_dependency "bundler", "~> 2.0"
28
+ spec.add_development_dependency "git"
29
+ spec.add_development_dependency "parse_a_changelog"
28
30
  spec.add_development_dependency "rake", "~> 13.0"
29
31
  spec.add_development_dependency "rspec", "~> 3.0"
30
32
  spec.add_development_dependency "rspec-its", "~> 1.2"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: static_collection
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Graham
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-18 00:00:00.000000000 Z
11
+ date: 2024-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: git
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: parse_a_changelog
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rake
43
71
  requirement: !ruby/object:Gem::Requirement
@@ -116,13 +144,14 @@ extensions: []
116
144
  extra_rdoc_files: []
117
145
  files:
118
146
  - ".github/CODEOWNERS"
119
- - ".github/workflows/main.yml"
147
+ - ".github/workflows/default.yaml"
120
148
  - ".github/workflows/stale.yml"
121
149
  - ".gitignore"
122
150
  - ".rspec"
123
151
  - ".rubocop.yml"
124
152
  - ".rubocop_todo.yml"
125
153
  - ".ruby-version"
154
+ - CHANGELOG.md
126
155
  - Gemfile
127
156
  - Gemfile.lock
128
157
  - LICENSE.txt
@@ -1,52 +0,0 @@
1
- ---
2
- name: Pipeline
3
- on: push
4
- concurrency:
5
- group: ${{ github.workflow }}-${{ github.ref }}
6
- cancel-in-progress: true
7
-
8
- jobs:
9
- build:
10
- name: Build
11
- runs-on: ubuntu-22.04
12
- strategy:
13
- matrix:
14
- ruby-version: [3.0.6, 3.1.4, 3.2.2]
15
- steps:
16
- - uses: actions/checkout@v3
17
- - name: Set up Ruby ${{ matrix.ruby-version }}
18
- uses: ruby/setup-ruby@v1
19
- with:
20
- bundler-cache: true
21
- ruby-version: ${{ matrix.ruby-version }}
22
- - name: Lint
23
- run: bundle exec rubocop
24
- - name: Test
25
- run: bundle exec rspec
26
-
27
- # Separate `release` job from `build`, as we only want release to be run once
28
- # and not run for each ruby version in the matrix:
29
- release:
30
- name: Release
31
- if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
32
- needs: build
33
- runs-on: ubuntu-22.04
34
- steps:
35
- - uses: actions/checkout@v3
36
- - uses: ruby/setup-ruby@v1
37
- with:
38
- bundler-cache: true
39
- - name: Release the gem
40
- run: |
41
- mkdir -p ~/.gem
42
- cat << EOF > ~/.gem/credentials
43
- ---
44
- :github: Bearer ${GITHUB_TOKEN}
45
- :rubygems_api_key: ${RUBYGEMS_API_KEY}
46
- EOF
47
- chmod 0600 ~/.gem/credentials
48
- git config user.email "noreply@wealthsimple.com"
49
- git config user.name "Wolfbot"
50
- bundle exec rake release
51
- env:
52
- RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}