hash_store 0.0.2 → 0.0.3
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/lib/hash_store/base.rb +7 -7
- data/lib/hash_store/version.rb +1 -1
- 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: 3e2a6831f333bc961fabbd75c1a76befa3f558e1
|
4
|
+
data.tar.gz: cc50c20c53d662875ab9f68ec67b2937b997f1ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7466ed78d318e5fc89178189eaf960e8f3327d5d127c7de9f3f54f30ceaa4dc712c0177ff0e178aa48e2f3010a5401fcc78f40196e2a1e66680f5541470fa98
|
7
|
+
data.tar.gz: a8cd54dd56d9c61843e84b3d5a0990bc7ebaa3c1aa5b88426590db82bf7ce91a886d8944870b59b3586fb750f9034091420494b27a1ff78e8ed600c91b22e3e2
|
data/lib/hash_store/base.rb
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
module HashStore::Base
|
4
4
|
module ClassMethods
|
5
5
|
def hash_store(name=nil, options={})
|
6
|
-
|
6
|
+
if !defined?(ActiveRecord::Base) || !self.ancestors.include?(ActiveRecord::Base)
|
7
7
|
begin
|
8
|
-
raise
|
9
|
-
raise
|
8
|
+
raise if options[:hash].nil?
|
9
|
+
raise if options[:key].nil?
|
10
10
|
rescue => e
|
11
11
|
print <<-EOS
|
12
12
|
When using hash_store on Non-ActiveRecord class, you MUST pass name and options(:key and :hash) arguments.
|
@@ -18,15 +18,15 @@ EOS
|
|
18
18
|
|
19
19
|
method_suffix = (name.nil? || name == '') ? '' : "_#{name}"
|
20
20
|
|
21
|
-
if options[:hash].
|
21
|
+
if !options[:hash].nil?
|
22
22
|
hs_hash_proc = options[:hash]
|
23
23
|
else
|
24
24
|
hs_hash_proc = ->(model){ model.as_json(root: false, except: [:created_at, :updated_at]) }
|
25
25
|
end
|
26
26
|
|
27
|
-
if options[:key].
|
27
|
+
if !options[:key].nil?
|
28
28
|
hs_key_proc = options[:key]
|
29
|
-
elsif
|
29
|
+
elsif method_suffix != '' && options[:key].nil?
|
30
30
|
hs_key_proc = ->(model){ "#{model.class.table_name}:#{name}:#{model.id}" }
|
31
31
|
else
|
32
32
|
hs_key_proc = ->(model){ "#{model.class.table_name}:#{model.id}" }
|
@@ -62,7 +62,7 @@ EOS
|
|
62
62
|
define_singleton_method "get_hash#{method_suffix}" do |key, options=nil|
|
63
63
|
json = HashStore::Config.redis.get(key)
|
64
64
|
return nil if json.nil?
|
65
|
-
return json if options.
|
65
|
+
return json if !options.nil? && options[:json]
|
66
66
|
MultiJson.decode(json)
|
67
67
|
end
|
68
68
|
|
data/lib/hash_store/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- M.Iwasaki(Curi)
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|