look_up_table 0.1.0.rc5 → 0.1.0.rc6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/look_up_table/version.rb +1 -1
- data/lib/look_up_table.rb +16 -10
- metadata +7 -7
data/lib/look_up_table.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
# TODO
|
1
|
+
# TODO:
|
2
2
|
# * move Methods to different modules
|
3
3
|
# * add private/protected
|
4
4
|
# * add class_names to CacheKey per default
|
5
5
|
# * if key allready used, transform values to array
|
6
6
|
# * somehow handle "cache-overflow"
|
7
|
+
# * use symbols freely
|
8
|
+
|
9
|
+
# FIXME:
|
10
|
+
# * Avoid @@class_variables, issues if "subclassed"
|
7
11
|
module LookUpTable
|
8
12
|
extend ActiveSupport::Concern
|
9
13
|
|
@@ -16,7 +20,8 @@ module LookUpTable
|
|
16
20
|
:batch_size => 10000,
|
17
21
|
:read_on_init => false,
|
18
22
|
:skip_memcached => false,
|
19
|
-
:sql_mode => true
|
23
|
+
:sql_mode => true.
|
24
|
+
:where => nil
|
20
25
|
}.merge(options)
|
21
26
|
|
22
27
|
self.lut_proc[lut_name.to_sym] = block
|
@@ -51,27 +56,27 @@ module LookUpTable
|
|
51
56
|
|
52
57
|
# Reloads allready loaded LUTs.
|
53
58
|
# Will also rewrites cache.
|
54
|
-
def lut_reload(name=nil)
|
59
|
+
def lut_reload(name = nil)
|
55
60
|
if name
|
56
61
|
lut_reset(name)
|
57
62
|
lut(name)
|
58
63
|
else
|
59
64
|
lut_keys.each { |k| lut_reload(k) }
|
60
65
|
end
|
66
|
+
|
67
|
+
return lut_keys
|
61
68
|
end
|
62
69
|
|
63
70
|
# Init complete LUT with all keys define.
|
64
71
|
# But won't rewrite cache if allready written!
|
65
|
-
def lut_init(name=nil)
|
72
|
+
def lut_init(name = nil)
|
66
73
|
if name
|
67
74
|
lut(name)
|
68
75
|
else
|
69
|
-
lut_keys.each
|
70
|
-
lut_init(key)
|
71
|
-
end
|
76
|
+
lut_keys.each { |k| lut_init(k) }
|
72
77
|
end
|
73
78
|
|
74
|
-
return
|
79
|
+
return lut_keys
|
75
80
|
end
|
76
81
|
|
77
82
|
|
@@ -134,7 +139,7 @@ module LookUpTable
|
|
134
139
|
lut = {}
|
135
140
|
block = lut_proc(name)
|
136
141
|
|
137
|
-
self.find_in_batches(:batch_size => lut_options(name)[:batch_size]) do |items|
|
142
|
+
self.where(lut_options(name)[:where]).find_in_batches(:batch_size => lut_options(name)[:batch_size]) do |items| #FIXME not DRY here
|
138
143
|
items.each do |item|
|
139
144
|
if block
|
140
145
|
block.call(lut, item)
|
@@ -178,6 +183,7 @@ module LookUpTable
|
|
178
183
|
lut = {}
|
179
184
|
|
180
185
|
while item = lut_read_cache_item(name, i)
|
186
|
+
# HACK: merge will override existing values
|
181
187
|
lut.merge!(item) if item
|
182
188
|
i += 1
|
183
189
|
end
|
@@ -206,7 +212,7 @@ module LookUpTable
|
|
206
212
|
def lut_write_to_cache_sql_mode(name)
|
207
213
|
batch_count = 0
|
208
214
|
|
209
|
-
self.find_in_batches(:batch_size => lut_options(name)[:batch_size]) do |items|
|
215
|
+
self.where(lut_options(name)[:where]).find_in_batches(:batch_size => lut_options(name)[:batch_size]) do |items| #FIXME not DRY here
|
210
216
|
lut = {}
|
211
217
|
block = lut_proc(name)
|
212
218
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: look_up_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0.
|
4
|
+
version: 0.1.0.rc6
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-11-01 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &86496530 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 3.1.1
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *86496530
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sqlite3
|
27
|
-
requirement: &
|
27
|
+
requirement: &86496070 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *86496070
|
36
36
|
description: A simple LookUpTable to cache large (!) and static(!) data
|
37
37
|
email:
|
38
38
|
- ph@werbeboten.de
|
@@ -102,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
102
|
version: '0'
|
103
103
|
segments:
|
104
104
|
- 0
|
105
|
-
hash:
|
105
|
+
hash: 506016211
|
106
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
107
|
none: false
|
108
108
|
requirements:
|