api_hammer 0.3.0 → 0.3.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 +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/api_hammer/active_record_cache_find_by.rb +1 -1
- data/lib/api_hammer/version.rb +1 -1
- data/test/active_record_cache_find_by_test.rb +16 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47d49032018338bda7b3582ad0ee4ced9872023f
|
4
|
+
data.tar.gz: f29e3cddca5d09853af22dabeec7f1aaaa3bc809
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25525ad6d1eda4cbb4d9b61cbcf270a91255fa10278bb89774cdabdafb85d4a5ef591f5d9725759d557a3763ac1fbbbc148e394242cc562b8ad97e938ebdf8bd
|
7
|
+
data.tar.gz: 6ac7d6ea07947ed9a6b5dbf0a6a407d3e275cf53b762fdf7a0ff031422cbf3c832e7b9a2c8e1b7258d58ebf90a631bc9e616418aea619d1e8488120320115cad
|
data/CHANGELOG.md
CHANGED
@@ -33,7 +33,7 @@ module ActiveRecord
|
|
33
33
|
can_cache &&= cache_find_bys &&
|
34
34
|
!loaded? && # if it's loaded no need to hit cache
|
35
35
|
where_values.all? { |wv| wv.is_a?(Arel::Nodes::Equality) } && # no inequality or that sort of thing
|
36
|
-
cache_find_bys.include?(where_values.map { |wv| wv.left.name }.sort) && # any of the set of where-values to cache match this relation
|
36
|
+
cache_find_bys.include?(where_values.map { |wv| wv.left.name.to_s }.sort) && # any of the set of where-values to cache match this relation
|
37
37
|
where_values.map(&actual_right).all? { |r| r.is_a?(String) || r.is_a?(Numeric) } && # check all right side values are simple types, number or string
|
38
38
|
offset_value.nil? &&
|
39
39
|
joins_values.blank? &&
|
data/lib/api_hammer/version.rb
CHANGED
@@ -24,16 +24,24 @@ ActiveRecord::Schema.define do
|
|
24
24
|
table.column :title, :string
|
25
25
|
table.column :performer, :string
|
26
26
|
table.column :tracks, :integer
|
27
|
+
table.column :catalog_xid, :integer
|
28
|
+
end
|
29
|
+
create_table :catalogs do |table|
|
27
30
|
end
|
28
31
|
end
|
29
32
|
|
30
33
|
class Album < ActiveRecord::Base
|
34
|
+
belongs_to :catalog, :foreign_key => :catalog_xid
|
31
35
|
cache_find_by(:id)
|
32
36
|
cache_find_by(:performer)
|
33
37
|
cache_find_by(:title, :performer)
|
34
38
|
cache_find_by(:tracks)
|
35
39
|
end
|
36
40
|
|
41
|
+
class Catalog < ActiveRecord::Base
|
42
|
+
has_many :albums, :foreign_key => :catalog_xid
|
43
|
+
end
|
44
|
+
|
37
45
|
class VinylAlbum < Album
|
38
46
|
self.finder_cache = ActiveSupport::Cache::MemoryStore.new
|
39
47
|
end
|
@@ -198,4 +206,12 @@ describe 'ActiveRecord::Base.cache_find_by' do
|
|
198
206
|
Album.where(:performer => 'y', :title => 'x').first
|
199
207
|
assert_equal 'z', Album.where(:performer => 'y/title/x').first.title
|
200
208
|
end
|
209
|
+
|
210
|
+
it 'works with a symbol on the left' do
|
211
|
+
# this makes an association with :catalog_xid as the left side of a where_value. these are usually
|
212
|
+
# strings. this just makes sure it doesn't error out.
|
213
|
+
c = Catalog.create!
|
214
|
+
c = Catalog.first
|
215
|
+
c.albums.where(:title => 'y').first
|
216
|
+
end
|
201
217
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_hammer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|