constant_table_saver 5.1.0 → 5.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +85 -0
- data/lib/constant_table_saver/version.rb +1 -1
- data/test/constant_table_saver_test.rb +1 -1
- metadata +2 -2
- data/README +0 -67
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd0a0f0466a9358d62172e153ae85c8a88a0e9a9
|
4
|
+
data.tar.gz: b6d62a665e5a4b179101924c320e3ca2dd773e35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 350eef086260e755159c68fa837515eff1c50f79b90a6044fb3ecdc806b78955faa9ba5716e73ad0b92827e7bad2c3e11666a0914a872e7df086a195c9f7b205
|
7
|
+
data.tar.gz: 0d9a1eed230c95df417727e8693da32e9168b8dd428a49aee3cbf6d08e73e650824c9d453878d01a7de2461e31ad4b40792c142bf3a6267b0bd3c548de3ad4c9
|
data/README.md
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
ConstantTableSaver
|
2
|
+
==================
|
3
|
+
|
4
|
+
Loads all records from the table on first use, and thereafter returns the
|
5
|
+
cached (and frozen) records for all find calls.
|
6
|
+
|
7
|
+
Optionally, creates class-level methods you can use to grab the records,
|
8
|
+
named after the name field you specify.
|
9
|
+
|
10
|
+
|
11
|
+
Compatibility
|
12
|
+
=============
|
13
|
+
|
14
|
+
Currently tested against Rails 5.1 (5.1.0beta2) and 5.0 (up to 5.0.2) and 4.2 (up to 4.2.7), on Ruby 2.3.4.
|
15
|
+
|
16
|
+
For earlier versions of Rails, use an older version of the gem.
|
17
|
+
|
18
|
+
|
19
|
+
Example
|
20
|
+
=======
|
21
|
+
|
22
|
+
Problem: the following code would load each txn_type individually:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
Txn.all.each {|txn| .. do something with txn.txn_type ..}
|
26
|
+
```
|
27
|
+
|
28
|
+
You can improve this a bit with standard Rails:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
Txn.preload(:txn_type).all.each {|txn| .. do something with txn.txn_type ..}
|
32
|
+
```
|
33
|
+
|
34
|
+
This would load the txn_types in one go after the txns query, but would still need a query every time you load txns.
|
35
|
+
|
36
|
+
But if you use constant_table_saver, without needing to use a preload:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
class TxnType
|
40
|
+
constant_table
|
41
|
+
end
|
42
|
+
|
43
|
+
Txn.all.each {|txn| .. do something with txn.txn_type ..}
|
44
|
+
```
|
45
|
+
|
46
|
+
It will no longer requires individual txn_type loads, just every time you start the server (or every request, in development mode). Most other basic queries are also cached:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
TxnType.all.to_a
|
50
|
+
```
|
51
|
+
|
52
|
+
But other scopes with options still result in actual queries:
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
TxnType.where("name LIKE '%foo%'").to_a
|
56
|
+
TxnType.lock.find(2)
|
57
|
+
```
|
58
|
+
|
59
|
+
|
60
|
+
You can also use:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
class TxnType
|
64
|
+
constant_table :name => :label
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
Which if you have:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
TxnType.create!(:label => "Customer Purchase")
|
72
|
+
TxnType.create!(:label => "Refund")
|
73
|
+
```
|
74
|
+
|
75
|
+
Means you will also have methods returning those records:
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
TxnType.customer_purchase
|
79
|
+
TxnType.refund
|
80
|
+
```
|
81
|
+
|
82
|
+
Optionally, you can specify a `:name_prefix` and/or `:name_suffix`.
|
83
|
+
|
84
|
+
|
85
|
+
Copyright (c) 2010-2017 Will Bryant, Sekuda Ltd, released under the MIT license
|
@@ -161,7 +161,7 @@ class ConstantTableSaverTest < ActiveSupport::TestCase
|
|
161
161
|
end
|
162
162
|
|
163
163
|
test "it passes the options preventing caching to the underlying query methods" do
|
164
|
-
assert_nil
|
164
|
+
assert_nil ConstantPie.where(:filling => 'unicorn').first
|
165
165
|
assert_equal [], ConstantPie.where(:filling => 'unicorn').all
|
166
166
|
end
|
167
167
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: constant_table_saver
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.1.
|
4
|
+
version: 5.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Will Bryant
|
@@ -74,7 +74,7 @@ files:
|
|
74
74
|
- ".gitignore"
|
75
75
|
- Gemfile
|
76
76
|
- MIT-LICENSE
|
77
|
-
- README
|
77
|
+
- README.md
|
78
78
|
- Rakefile
|
79
79
|
- constant_table_saver.gemspec
|
80
80
|
- init.rb
|
data/README
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
ConstantTableSaver
|
2
|
-
==================
|
3
|
-
|
4
|
-
Loads all records from the table on first use, and thereafter returns the
|
5
|
-
cached (and frozen) records for all find calls.
|
6
|
-
|
7
|
-
Optionally, creates class-level methods you can use to grab the records,
|
8
|
-
named after the name field you specify.
|
9
|
-
|
10
|
-
|
11
|
-
Compatibility
|
12
|
-
=============
|
13
|
-
|
14
|
-
Currently tested against Rails 5.1 (5.1.0beta2) and 5.0 (up to 5.0.2) and 4.2 (up to 4.2.7), on Ruby 2.3.4.
|
15
|
-
|
16
|
-
For earlier versions of Rails, use an older version of the gem.
|
17
|
-
|
18
|
-
|
19
|
-
Example
|
20
|
-
=======
|
21
|
-
|
22
|
-
Txn.all.each {|txn| .. do something with txn.txn_type ..}
|
23
|
-
- would load each txn_type individually
|
24
|
-
|
25
|
-
Txn.all(:include => :txn_type).each {|txn| .. do something with txn.txn_type ..}
|
26
|
-
- would load the txn_types in one go after the txns query, but would still need
|
27
|
-
a query every time you load txns
|
28
|
-
|
29
|
-
|
30
|
-
But if you use:
|
31
|
-
|
32
|
-
class TxnType
|
33
|
-
constant_table
|
34
|
-
end
|
35
|
-
|
36
|
-
Txn.all.each {|txn| .. do something with txn.txn_type ..}
|
37
|
-
- no longer requires individual txn_type loads, just every time you start the
|
38
|
-
server (or every request, in development mode)
|
39
|
-
|
40
|
-
TxnType.all
|
41
|
-
- also cached, but:
|
42
|
-
|
43
|
-
TxnType.all(:conditions => "name LIKE '%foo%'")
|
44
|
-
TxnType.find(2, :lock => true)
|
45
|
-
- all still result in traditional finds, since you gave options
|
46
|
-
|
47
|
-
|
48
|
-
You can also use:
|
49
|
-
|
50
|
-
class TxnType
|
51
|
-
constant_table :name => :label
|
52
|
-
end
|
53
|
-
|
54
|
-
Which if you have:
|
55
|
-
|
56
|
-
TxnType.create!(:label => "Customer Purchase")
|
57
|
-
TxnType.create!(:label => "Refund")
|
58
|
-
|
59
|
-
Means you will also have methods returning those records:
|
60
|
-
|
61
|
-
TxnType.customer_purchase
|
62
|
-
TxnType.refund
|
63
|
-
|
64
|
-
Optionally, you can specify a :name_prefix and/or :name_suffix.
|
65
|
-
|
66
|
-
|
67
|
-
Copyright (c) 2010-2013 Will Bryant, Sekuda Ltd, released under the MIT license
|