static_collection 0.3.1 → 0.4.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: c35ba8c77c61ddfaf666a7b9a0be2a0ba9580ec568e6fbc7c5269590d300607b
4
- data.tar.gz: a85d58e434c5d0dc7506016376d65b93e9715c55077ca7698cf637ab5eee76d5
3
+ metadata.gz: 4bdcf2327cbd67bd3a580c9be6a96c96d104e04462970d8abf97139fd05f252d
4
+ data.tar.gz: b8a83baba3ba4eebc5019ddf6825635f0a95a77c793b02030021fe32ec0e3676
5
5
  SHA512:
6
- metadata.gz: 6639c1ad20a1ab0311597e4ef172b83b42ed15e5261948090314097f3b5464c4ceed9eda7516f162915409d70eb41c7d42586a4c50585c8f8eba7aa5b81b8e23
7
- data.tar.gz: 9dcbf439545dfbe7f5de03d6415ed1205dab7a221e4637400b8260b0f1b6028bf5ae44fcde78ee0e0f77abf48cda4241da07a19a6b1a8561e944b4177fe97b79
6
+ metadata.gz: 93f9f93d7b45466de470ccafc0b6d30272fbb9bada41598fb7e441b33ac3eb037bbeb2a81367de5f0601e947511247f0290ef2b813d75c75c0c2e5a51bf1b7bf
7
+ data.tar.gz: 07aaaee52c0854e04ce98ca5db1ab7dbbcf8aa81232590262343cd5a3960e85cb6190815f3a64ede2a58a8320278b8f7c5426c7a2a2490f97944ba481db160a0
@@ -8,12 +8,12 @@ concurrency:
8
8
  jobs:
9
9
  build:
10
10
  name: Build
11
- runs-on: ubuntu-20.04
11
+ runs-on: ubuntu-22.04
12
12
  strategy:
13
13
  matrix:
14
- ruby-version: [2.7.5, 3.0.3, 3.1.0, 3.2.0]
14
+ ruby-version: [3.1.4, 3.2.3, 3.3.0]
15
15
  steps:
16
- - uses: actions/checkout@v2
16
+ - uses: actions/checkout@v3
17
17
  - name: Set up Ruby ${{ matrix.ruby-version }}
18
18
  uses: ruby/setup-ruby@v1
19
19
  with:
@@ -30,9 +30,9 @@ jobs:
30
30
  name: Release
31
31
  if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master'
32
32
  needs: build
33
- runs-on: ubuntu-20.04
33
+ runs-on: ubuntu-22.04
34
34
  steps:
35
- - uses: actions/checkout@v2
35
+ - uses: actions/checkout@v3
36
36
  - uses: ruby/setup-ruby@v1
37
37
  with:
38
38
  bundler-cache: true
@@ -7,7 +7,7 @@ jobs:
7
7
  stale:
8
8
  runs-on: ubuntu-latest
9
9
  steps:
10
- - uses: actions/stale@v4
10
+ - uses: actions/stale@v8
11
11
  with:
12
12
  days-before-stale: 30
13
13
  days-before-close: 30
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  .rspec_status
12
12
 
13
13
  *.gem
14
+ vendor
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.5
1
+ 3.0.6
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## 0.4.0
9
+ ### Breaking Change
10
+ - All Static Collections will be now consist of frozen objects
11
+ - Reduce initialization of objects
data/Gemfile.lock CHANGED
@@ -1,79 +1,99 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- static_collection (0.3.1)
4
+ static_collection (0.4.0)
5
5
  activesupport (>= 4)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (7.0.4.2)
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)
15
20
  ast (2.4.2)
16
- concurrent-ruby (1.2.0)
21
+ base64 (0.2.0)
22
+ bigdecimal (3.1.6)
23
+ concurrent-ruby (1.2.3)
24
+ connection_pool (2.4.1)
17
25
  diff-lcs (1.5.0)
18
- i18n (1.12.0)
26
+ drb (2.2.0)
27
+ ruby2_keywords
28
+ i18n (1.14.1)
19
29
  concurrent-ruby (~> 1.0)
20
- json (2.6.3)
21
- minitest (5.17.0)
22
- parallel (1.22.1)
23
- parser (3.2.0.0)
30
+ json (2.7.1)
31
+ language_server-protocol (3.17.0.3)
32
+ minitest (5.21.2)
33
+ mutex_m (0.2.0)
34
+ parallel (1.24.0)
35
+ parser (3.3.0.4)
24
36
  ast (~> 2.4.1)
25
- rack (3.0.4.1)
37
+ racc
38
+ racc (1.7.3)
39
+ rack (3.0.8)
26
40
  rainbow (3.1.1)
27
- rake (10.5.0)
28
- regexp_parser (2.6.2)
29
- rexml (3.2.5)
41
+ rake (13.1.0)
42
+ regexp_parser (2.9.0)
43
+ rexml (3.2.6)
30
44
  rspec (3.12.0)
31
45
  rspec-core (~> 3.12.0)
32
46
  rspec-expectations (~> 3.12.0)
33
47
  rspec-mocks (~> 3.12.0)
34
- rspec-core (3.12.0)
48
+ rspec-core (3.12.2)
35
49
  rspec-support (~> 3.12.0)
36
- rspec-expectations (3.12.2)
50
+ rspec-expectations (3.12.3)
37
51
  diff-lcs (>= 1.2.0, < 2.0)
38
52
  rspec-support (~> 3.12.0)
39
53
  rspec-its (1.3.0)
40
54
  rspec-core (>= 3.0.0)
41
55
  rspec-expectations (>= 3.0.0)
42
- rspec-mocks (3.12.3)
56
+ rspec-mocks (3.12.6)
43
57
  diff-lcs (>= 1.2.0, < 2.0)
44
58
  rspec-support (~> 3.12.0)
45
- rspec-support (3.12.0)
46
- rubocop (1.44.1)
59
+ rspec-support (3.12.1)
60
+ rubocop (1.60.1)
47
61
  json (~> 2.3)
62
+ language_server-protocol (>= 3.17.0)
48
63
  parallel (~> 1.10)
49
- parser (>= 3.2.0.0)
64
+ parser (>= 3.3.0.2)
50
65
  rainbow (>= 2.2.2, < 4.0)
51
66
  regexp_parser (>= 1.8, < 3.0)
52
67
  rexml (>= 3.2.5, < 4.0)
53
- rubocop-ast (>= 1.24.1, < 2.0)
68
+ rubocop-ast (>= 1.30.0, < 2.0)
54
69
  ruby-progressbar (~> 1.7)
55
70
  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)
71
+ rubocop-ast (1.30.0)
72
+ parser (>= 3.2.1.0)
73
+ rubocop-capybara (2.20.0)
59
74
  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)
75
+ rubocop-factory_bot (2.25.1)
76
+ rubocop (~> 1.41)
77
+ rubocop-performance (1.20.2)
78
+ rubocop (>= 1.48.1, < 2.0)
79
+ rubocop-ast (>= 1.30.0, < 2.0)
80
+ rubocop-rails (2.23.1)
64
81
  activesupport (>= 4.2.0)
65
82
  rack (>= 1.1)
66
83
  rubocop (>= 1.33.0, < 2.0)
67
- rubocop-rspec (2.18.1)
68
- rubocop (~> 1.33)
84
+ rubocop-ast (>= 1.30.0, < 2.0)
85
+ rubocop-rspec (2.26.1)
86
+ rubocop (~> 1.40)
69
87
  rubocop-capybara (~> 2.17)
70
- rubocop-vendor (0.8.10)
71
- rubocop (>= 0.53.0)
72
- ruby-progressbar (1.11.0)
88
+ rubocop-factory_bot (~> 2.22)
89
+ rubocop-vendor (0.13.0)
90
+ rubocop
91
+ ruby-progressbar (1.13.0)
92
+ ruby2_keywords (0.0.5)
73
93
  tzinfo (2.0.6)
74
94
  concurrent-ruby (~> 1.0)
75
- unicode-display_width (2.4.2)
76
- ws-style (6.14.4)
95
+ unicode-display_width (2.5.0)
96
+ ws-style (6.14.7)
77
97
  rubocop (>= 1.36)
78
98
  rubocop-performance (>= 1.10.2)
79
99
  rubocop-rails (>= 2.9.1)
@@ -85,7 +105,7 @@ PLATFORMS
85
105
 
86
106
  DEPENDENCIES
87
107
  bundler (~> 2.0)
88
- rake (~> 10.0)
108
+ rake (~> 13.0)
89
109
  rspec (~> 3.0)
90
110
  rspec-its (~> 1.2)
91
111
  rubocop (~> 1.2)
@@ -93,4 +113,4 @@ DEPENDENCIES
93
113
  ws-style
94
114
 
95
115
  BUNDLED WITH
96
- 2.2.32
116
+ 2.2.33
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.1".freeze
2
+ VERSION = "0.4.0".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
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://github.com/wealthsimple/static_collection"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.required_ruby_version = '>= 2.7.5'
16
+ spec.required_ruby_version = '>= 3.0'
17
17
 
18
18
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
19
  f.match(%r{^(test|spec|features)/})
@@ -25,7 +25,7 @@ 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 "rake", "~> 10.0"
28
+ spec.add_development_dependency "rake", "~> 13.0"
29
29
  spec.add_development_dependency "rspec", "~> 3.0"
30
30
  spec.add_development_dependency "rspec-its", "~> 1.2"
31
31
  spec.add_development_dependency "rubocop", "~> 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.1
4
+ version: 0.4.0
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-02-03 00:00:00.000000000 Z
11
+ date: 2024-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '10.0'
47
+ version: '13.0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '10.0'
54
+ version: '13.0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -123,6 +123,7 @@ files:
123
123
  - ".rubocop.yml"
124
124
  - ".rubocop_todo.yml"
125
125
  - ".ruby-version"
126
+ - CHANGELOG.md
126
127
  - Gemfile
127
128
  - Gemfile.lock
128
129
  - LICENSE.txt
@@ -146,14 +147,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
147
  requirements:
147
148
  - - ">="
148
149
  - !ruby/object:Gem::Version
149
- version: 2.7.5
150
+ version: '3.0'
150
151
  required_rubygems_version: !ruby/object:Gem::Requirement
151
152
  requirements:
152
153
  - - ">="
153
154
  - !ruby/object:Gem::Version
154
155
  version: '0'
155
156
  requirements: []
156
- rubygems_version: 3.1.6
157
+ rubygems_version: 3.2.33
157
158
  signing_key:
158
159
  specification_version: 4
159
160
  summary: Run queries against static data.