support_table 1.0.0 → 1.0.1

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: e6446caaf1ed0561e4fc98214a72e30fae6fc70aa7ef868aa6e6a17f4dc4f621
4
- data.tar.gz: 9f7739af82443b3279bf74cb1262370284fc0c3554f42a3dc1d5d254c176d4a5
3
+ metadata.gz: ec98ef0a0766ba05d7b2e7549e4bf334ed0a897ef33b9dc4dad9b4dc22d09be3
4
+ data.tar.gz: d9ccf2f45ba8e081d9628bd582adca1bd2b35962a566898e5324d907f1d34677
5
5
  SHA512:
6
- metadata.gz: ddb606d4d8674bb335dad19888ee531aafe2d8790396bbfde7ab6ea574fb20b3b01aa0d599ac2f43720d6ecca1709f0318c2ab42f4f9749c259f1b75462ae451
7
- data.tar.gz: 22cfa034d8062e57d5e7eff49a532f97d293bb2a7847392f57388ebc7e40530df91dfd452be58131e45c3fd6798a39bcb3215a5d8775307e878e0fd19327ac05
6
+ metadata.gz: 046af81a21a3295ecfe9154a2eeed550fadf8fb46c291477dd0db88e29249f3ab6c94854dede0f44b0b59f0a3c7bc83436b59b13c7b3dec9c208ad555a448ee8
7
+ data.tar.gz: 8683d3986451d309a952bea1a105e6c054b7cfe715647fc09db5b83ec464e3ca55118014e8f740a19478cfa67f637ed721892853b6b6d888d3ac5227d434ede9
data/CHANGELOG.md CHANGED
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## 1.0.1
8
+
9
+ ### Fixed
10
+
11
+ - Passing `cache: nil` to the `support_table` method now disables caching as documented. Previously it fell back to using the global cache.
12
+
7
13
  ## 1.0.0
8
14
 
9
15
  ### Added
data/README.md CHANGED
@@ -104,10 +104,10 @@ Data will be automatically synced to the database whenever you run any of the fo
104
104
 
105
105
  You can also manually trigger synchronization with the `support_table_data:sync` rake task.
106
106
 
107
- You **must** popululate the support table data in your test database during your deploy process or test suite setup to ensure that the data is present when your application code runs.
107
+ You **must** populate the support table data in your test database during your deploy process or test suite setup to ensure that the data is present when your application code runs.
108
108
 
109
109
  > [!TIP]
110
- > You can also call `SupportTable.sync_all!` in from your application code to synchronize the data.
110
+ > You can also call `SupportTable.sync_all!` from your application code to synchronize the data.
111
111
 
112
112
  #### Advanced Data Settings
113
113
 
@@ -115,7 +115,7 @@ You can customize the behavior of the support table data syncing by passing opti
115
115
 
116
116
  ##### Key Attribute
117
117
 
118
- One of the attributes on the table will be used as the unique identifier for each row in the YAML file. By default, this is will be the primary key on the table. You can set a different attribute by passing the `key_attribute` option.
118
+ One of the attributes on the table will be used as the unique identifier for each row in the YAML file. By default, this will be the `id` attribute. You can set a different attribute by passing the `key_attribute` option.
119
119
 
120
120
  ```ruby
121
121
  class Status < ApplicationRecord
@@ -140,6 +140,8 @@ class Status < ApplicationRecord
140
140
  end
141
141
  ```
142
142
 
143
+ You can pass `data_file: false` if you don't want to load data from the default data file.
144
+
143
145
  You can also change the base directory for all support table data files by setting `SupportTable.data_directory` in your application configuration (e.g., in an initializer).
144
146
 
145
147
  ```ruby
@@ -186,7 +188,10 @@ You can use any of the DSL methods defined in that gem to further customize how
186
188
 
187
189
  ### Caching
188
190
 
189
- Support table data is often read frequently but changes rarely. To improve performance, lookups from support tables by the key attribute are cached by default. Any query that queries a record by the key attribute (i.e. `find_by(name: "Draft")` if `name` is the key attribute) will use the cache. The `id` column is also always cacheable so `find(1)` or `find_by(id: 1)` will also use the cache.
191
+ Support table data is often read frequently but changes rarely. To improve performance, lookups from support tables by the key attribute are cached by default. Any `find_by` query that looks up a record by the key attribute (i.e. `find_by(name: "Draft")` if `name` is the key attribute) will use the cache. The `id` column is also always cacheable so `find_by(id: 1)` will also use the cache.
192
+
193
+ > [!NOTE]
194
+ > Only `find_by`, `find_by!`, and `fetch_by` lookups use the cache. Calling `find(1)` will always query the database.
190
195
 
191
196
  You can use the `fetch_by` method to better express in your code that the lookup is using a cache. This method is an alias for `find_by` except that it will raise an error if the lookup is not using a cache on that attribute.
192
197
 
@@ -242,6 +247,9 @@ class Status < ApplicationRecord
242
247
  end
243
248
  ```
244
249
 
250
+ > [!NOTE]
251
+ > Disabling the cache only affects `find_by` lookups on the model itself. Other models with a `belongs_to_support_table` association to the model may still cache the association reads in the global cache.
252
+
245
253
  You can specify the value `:memory` to use an in memory cache. This is the default behavior.
246
254
 
247
255
  ```ruby
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.0.1
@@ -1,4 +1,4 @@
1
- # frozen_string_leteral: true
1
+ # frozen_string_literal: true
2
2
 
3
3
  module SupportTable
4
4
  # Class to define support table behavior on an ActiveRecord class.
@@ -61,7 +61,7 @@ module SupportTable
61
61
  end
62
62
 
63
63
  def setup_caching(cache_by, cache, ttl)
64
- if cache == false
64
+ if cache == false || cache.nil?
65
65
  klass.send(:cache_by, false)
66
66
  return
67
67
  end
data/lib/support_table.rb CHANGED
@@ -43,16 +43,16 @@ module SupportTable
43
43
  # you need to override any of the defaults. See SupportTableData and SupportTableCache
44
44
  # for more details.
45
45
  #
46
- # @param data_file [String, Array<String>, nil] Path to the data file to use to load the table. This
46
+ # @param data_file [String, Array<String>, false, nil] Path to the data file to use to load the table. This
47
47
  # should be a YAML, JSON, or CSV file that defines the records that should always exist in
48
48
  # the table. If no value is specified, then a YAML file in the data directory with the
49
49
  # same name as the underscored, pluralized name of the class will be used. For example,
50
50
  # if the class name is `Task::Status`, then it will look for the file `task/statuses.yml`
51
- # in the `db/support_tables` directory.
51
+ # in the `db/support_tables` directory. You can pass `false` to disable loading the
52
+ # default data file.
52
53
  #
53
54
  # @param key_attribute [String, Symbol, nil] The name of the attribute in the data file that
54
- # uniquely identifies each row in the data. By default this will be the primary key
55
- # attribute of the table (usually `id`).
55
+ # uniquely identifies each row in the data. By default this will be the `id` attribute.
56
56
  #
57
57
  # @param attribute_helpers [String, Symbol, Array<String, Symbol>, nil] List of attributes
58
58
  # which should have helper methods created for them. This generates methods for each named instance
@@ -65,10 +65,11 @@ module SupportTable
65
65
  #
66
66
  # @param cache [ActiveSupport::Cache::Store, Symbol, Boolean, nil] The caching mechanism to use.
67
67
  # This can be either an instance of `ActiveSupport::Cache::Store` like `Rails.cache`, or
68
- # the value `:memory` to use an in-memory cache, or `false` to disable caching.
68
+ # the value `:memory` to use an in-memory cache, or `false` or `nil` to disable caching.
69
69
  #
70
+ # @param ttl [Numeric, ActiveSupport::Duration, nil] The time-to-live (in seconds) for cached
71
+ # records. If not specified, cached records never expire.
70
72
  #
71
- # @param ttl [Numeric, ActiveSupport::Duration, nil] The time-to-live (in seconds) for cached records. If not specified,
72
73
  # @return [void]
73
74
  def support_table(data_file: nil, key_attribute: nil, attribute_helpers: nil, cache_by: nil, cache: :memory, ttl: nil)
74
75
  SupportTable::Definition.new(self).support_table(
@@ -35,8 +35,8 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.require_paths = ["lib"]
37
37
 
38
+ spec.required_ruby_version = ">= 2.6"
39
+
38
40
  spec.add_dependency "support_table_cache", "~> 1.1", ">= 1.1.5"
39
41
  spec.add_dependency "support_table_data", "~> 1.5", ">= 1.5.0"
40
-
41
- spec.add_development_dependency "bundler"
42
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: support_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Durand
@@ -49,20 +49,6 @@ dependencies:
49
49
  - - ">="
50
50
  - !ruby/object:Gem::Version
51
51
  version: 1.5.0
52
- - !ruby/object:Gem::Dependency
53
- name: bundler
54
- requirement: !ruby/object:Gem::Requirement
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- version: '0'
59
- type: :development
60
- prerelease: false
61
- version_requirements: !ruby/object:Gem::Requirement
62
- requirements:
63
- - - ">="
64
- - !ruby/object:Gem::Version
65
- version: '0'
66
52
  email:
67
53
  - bbdurand@gmail.com
68
54
  executables: []
@@ -91,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
77
  requirements:
92
78
  - - ">="
93
79
  - !ruby/object:Gem::Version
94
- version: '0'
80
+ version: '2.6'
95
81
  required_rubygems_version: !ruby/object:Gem::Requirement
96
82
  requirements:
97
83
  - - ">="