ssdb-attr 0.0.6 → 0.0.7
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/Gemfile.lock +1 -1
- data/lib/ssdb-attr/version.rb +1 -1
- data/lib/ssdb/attr.rb +11 -4
- data/test/ssdb_attr_test.rb +18 -2
- 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: 8a0f7707b5bd4d3ab16f2eca649707537455d72b
|
4
|
+
data.tar.gz: 5fdab1774f844fa38f07ebcc704b999cd1ecb5ed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c255affeb6d9db640c95256c2f648bb7310c7b58c5e8589ee44a81ad8d29528e299bc0ad4a53e9b8a0e896806a8d96c23b9d27fe4b082ae52b7195a8794c4ca
|
7
|
+
data.tar.gz: 2d1d2018691436d97ef4b9e482e73141999ec5e5223129b77b9540bd918d6bc12fe097079eef98a193980da804932109eeb3f0489fa1810913c23b8e0599d9c9
|
data/Gemfile.lock
CHANGED
data/lib/ssdb-attr/version.rb
CHANGED
data/lib/ssdb/attr.rb
CHANGED
@@ -43,7 +43,15 @@ module SSDB
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def to_ssdb_attr_key(name)
|
46
|
-
self.class
|
46
|
+
klass = self.class
|
47
|
+
|
48
|
+
custom_id = klass.instance_variable_get("@ssdb_attr_id")
|
49
|
+
|
50
|
+
if custom_id.present?
|
51
|
+
"#{klass.name.tableize}:#{self.send(custom_id)}:#{name}"
|
52
|
+
else
|
53
|
+
"#{klass.name.tableize}:#{id}:#{name}"
|
54
|
+
end
|
47
55
|
end
|
48
56
|
|
49
57
|
private
|
@@ -57,11 +65,10 @@ module SSDB
|
|
57
65
|
@ssdb_attr_names ||= []
|
58
66
|
end
|
59
67
|
|
60
|
-
def
|
61
|
-
|
68
|
+
def ssdb_attr_id(sym)
|
69
|
+
@ssdb_attr_id = sym
|
62
70
|
end
|
63
71
|
|
64
|
-
|
65
72
|
# ssdb_attr :content, :string, default: 0, touch: true
|
66
73
|
# ssdb_attr :writer_version, :integer, default: 0, touch: [:field1, :field2, :field3]
|
67
74
|
#
|
data/test/ssdb_attr_test.rb
CHANGED
@@ -19,6 +19,10 @@ def setup!
|
|
19
19
|
{ 'posts' => 'updated_at DATETIME, saved_at DATETIME, changed_at DATETIME' }.each do |table_name, columns_as_sql_string|
|
20
20
|
ActiveRecord::Base.connection.execute "CREATE TABLE #{table_name} (id INTEGER NOT NULL PRIMARY KEY, #{columns_as_sql_string})"
|
21
21
|
end
|
22
|
+
|
23
|
+
{ 'chat_messages' => 'uuid VARCHAR' }.each do |table_name, columns_as_sql_string|
|
24
|
+
ActiveRecord::Base.connection.execute "CREATE TABLE #{table_name} (id INTEGER NOT NULL PRIMARY KEY, #{columns_as_sql_string})"
|
25
|
+
end
|
22
26
|
end
|
23
27
|
|
24
28
|
setup!
|
@@ -50,6 +54,13 @@ class Post < ActiveRecord::Base
|
|
50
54
|
end
|
51
55
|
end
|
52
56
|
|
57
|
+
class ChatMessage < ActiveRecord::Base
|
58
|
+
include SSDB::Attr
|
59
|
+
|
60
|
+
ssdb_attr :content, :string
|
61
|
+
ssdb_attr_id :uuid
|
62
|
+
end
|
63
|
+
|
53
64
|
class SsdbAttrTest < test_framework
|
54
65
|
def setup
|
55
66
|
SSDBAttr.pool.with { |conn| conn.flushdb }
|
@@ -57,6 +68,7 @@ class SsdbAttrTest < test_framework
|
|
57
68
|
ActiveRecord::Base.connection.execute "DELETE FROM #{table}"
|
58
69
|
end
|
59
70
|
@post = Post.create(updated_at: 1.day.ago, saved_at: 1.day.ago, changed_at: 1.day.ago)
|
71
|
+
@chat_message = ChatMessage.create(uuid: SecureRandom.uuid)
|
60
72
|
end
|
61
73
|
|
62
74
|
def test_respond_to_methods
|
@@ -95,7 +107,11 @@ class SsdbAttrTest < test_framework
|
|
95
107
|
end
|
96
108
|
|
97
109
|
def test_to_ssdb_attr_key
|
98
|
-
assert_equal "posts:#{@post.id}:name",
|
110
|
+
assert_equal "posts:#{@post.id}:name", @post.to_ssdb_attr_key("name")
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_custom_ssdb_attr_id
|
114
|
+
assert_equal "chat_messages:#{@chat_message.uuid}:content", @chat_message.to_ssdb_attr_key("content")
|
99
115
|
end
|
100
116
|
|
101
117
|
def test_update_ssdb_attrs_with_symbolize_keys
|
@@ -137,7 +153,7 @@ class SsdbAttrTest < test_framework
|
|
137
153
|
default_title_key = @post.to_ssdb_attr_key(:default_title)
|
138
154
|
version_key = @post.to_ssdb_attr_key(:version)
|
139
155
|
|
140
|
-
assert_equal
|
156
|
+
assert_equal 10, SSDBAttr.pool.with { |conn| conn.keys.count }
|
141
157
|
assert_equal true, SSDBAttr.pool.with { |conn| conn.exists(title_key) }
|
142
158
|
assert_equal "Untitled", SSDBAttr.pool.with { |conn| conn.get(default_title_key) }
|
143
159
|
assert_equal "1", SSDBAttr.pool.with { |conn| conn.get(version_key) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ssdb-attr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Larry Zhao
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: redis
|