enrichment_db 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/enrichment_db/db.rb +3 -13
- data/lib/enrichment_db/version.rb +1 -1
- metadata +2 -6
- data/lib/enrichment_db/cache.rb +0 -17
- data/test/cache_test.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 784632b18200a93e79ba0e9411dad4fa8fbba1f7
|
4
|
+
data.tar.gz: 22e53ab18054544013097f19600306f030bb270a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c16290deff38ea9f34469e63227a9f20a80821217d106e4371cfcfbbeb91f93e3a66b77f889f991de05ef1fd6baf9d4854afa4ed68150303682748bc678151b
|
7
|
+
data.tar.gz: ecd9cd06d69fc6356b9042fdc300291f46a8c06bfa2fc16e74b869357e2d9508b57b46dc96a74a9baa567503a2118b6dbe558cd0b0d1682ce22c6623abe803c7
|
data/lib/enrichment_db/db.rb
CHANGED
@@ -41,7 +41,9 @@ module EnrichmentDb
|
|
41
41
|
|
42
42
|
case type
|
43
43
|
when :select, 'select', '\d'
|
44
|
-
|
44
|
+
return EnrichmentDb::db_connection.exec(query, values) if values
|
45
|
+
|
46
|
+
EnrichmentDb::db_connection.exec(query)
|
45
47
|
when :insert, :drop, :delete, 'insert', 'drop', 'delete'
|
46
48
|
fail EnrichmentDb::RequestError, "Postgres method '#{type}' is unsupported"
|
47
49
|
else
|
@@ -49,18 +51,6 @@ module EnrichmentDb
|
|
49
51
|
end
|
50
52
|
end
|
51
53
|
|
52
|
-
def self.get_or_request(query, values = nil)
|
53
|
-
result = EnrichmentDb::Cache.get(query, values)
|
54
|
-
return result unless result.nil?
|
55
|
-
|
56
|
-
result = if values
|
57
|
-
EnrichmentDb::db_connection.exec(query, values)
|
58
|
-
else
|
59
|
-
EnrichmentDb::db_connection.exec(query)
|
60
|
-
end
|
61
|
-
EnrichmentDb::Cache.set(query, values, result)
|
62
|
-
end
|
63
|
-
|
64
54
|
def self.request_type(query)
|
65
55
|
result = query.downcase.match(/(^(?:drop|select|insert|delete|\\d))/)
|
66
56
|
return unless result
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enrichment_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Wallis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -69,7 +69,6 @@ files:
|
|
69
69
|
- lib/enrichment_db/.DS_Store
|
70
70
|
- lib/enrichment_db/ato.rb
|
71
71
|
- lib/enrichment_db/ato/datum.rb
|
72
|
-
- lib/enrichment_db/cache.rb
|
73
72
|
- lib/enrichment_db/census.rb
|
74
73
|
- lib/enrichment_db/census/datum.rb
|
75
74
|
- lib/enrichment_db/datum.rb
|
@@ -89,7 +88,6 @@ files:
|
|
89
88
|
- lib/enrichment_db/language.rb
|
90
89
|
- lib/enrichment_db/language/datum.rb
|
91
90
|
- lib/enrichment_db/version.rb
|
92
|
-
- test/cache_test.rb
|
93
91
|
- test/census/datum_test.rb
|
94
92
|
- test/datum_test.rb
|
95
93
|
- test/db_test.rb
|
@@ -140,7 +138,6 @@ test_files:
|
|
140
138
|
- lib/enrichment_db/.DS_Store
|
141
139
|
- lib/enrichment_db/ato.rb
|
142
140
|
- lib/enrichment_db/ato/datum.rb
|
143
|
-
- lib/enrichment_db/cache.rb
|
144
141
|
- lib/enrichment_db/census.rb
|
145
142
|
- lib/enrichment_db/census/datum.rb
|
146
143
|
- lib/enrichment_db/datum.rb
|
@@ -160,7 +157,6 @@ test_files:
|
|
160
157
|
- lib/enrichment_db/language.rb
|
161
158
|
- lib/enrichment_db/language/datum.rb
|
162
159
|
- lib/enrichment_db/version.rb
|
163
|
-
- test/cache_test.rb
|
164
160
|
- test/census/datum_test.rb
|
165
161
|
- test/datum_test.rb
|
166
162
|
- test/db_test.rb
|
data/lib/enrichment_db/cache.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}")
|
2
|
-
|
3
|
-
module EnrichmentDb::Cache
|
4
|
-
def self.get(query, values = nil)
|
5
|
-
query_cache(query, values)
|
6
|
-
end
|
7
|
-
|
8
|
-
def self.set(query, values = nil, result = nil)
|
9
|
-
query_cache(query, values, result)
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.query_cache(query, values, result = nil)
|
13
|
-
key = query + values.to_s
|
14
|
-
@query_cache ||= {}
|
15
|
-
@query_cache[key] ||= result
|
16
|
-
end
|
17
|
-
end
|
data/test/cache_test.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require "#{File.dirname(__FILE__)}/test_helper"
|
2
|
-
|
3
|
-
describe EnrichmentDb::Cache do
|
4
|
-
before do
|
5
|
-
EnrichmentDb::Cache.instance_variable_set(:@query_cache, nil)
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'should return nil as value hasn\'t been set when no values' do
|
9
|
-
query = 'do stuff'
|
10
|
-
assert_nil EnrichmentDb::Cache.get(query)
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'should return nil as value hasn\'t been set when non-empty values' do
|
14
|
-
query = 'do stuff'
|
15
|
-
values = ['er']
|
16
|
-
assert_nil EnrichmentDb::Cache.get(query, values)
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should set value on cache and get it' do
|
20
|
-
query = 'do stuff'
|
21
|
-
values = ['er']
|
22
|
-
record = 'This here is a gut dang it record'
|
23
|
-
set_result = EnrichmentDb::Cache.set(query, values, record)
|
24
|
-
|
25
|
-
get_result = EnrichmentDb::Cache.set(query, values)
|
26
|
-
|
27
|
-
refute_nil set_result
|
28
|
-
refute_nil get_result
|
29
|
-
assert_equal set_result, get_result
|
30
|
-
end
|
31
|
-
end
|