key_value 0.3.0 → 0.4.0
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.
- data/Readme.md +2 -3
- data/VERSION +1 -1
- data/key_value.gemspec +2 -2
- data/lib/key_value.rb +17 -4
- data/spec/key_value_spec.rb +7 -0
- data/spec/spec_helper.rb +2 -2
- metadata +4 -4
data/Readme.md
CHANGED
@@ -10,8 +10,8 @@ Migration
|
|
10
10
|
|
11
11
|
class CreateKeyValue < ActiveRecord::Migration
|
12
12
|
def self.up
|
13
|
-
create_table :key_values
|
14
|
-
t.string :key, :null => false
|
13
|
+
create_table :key_values do |t|
|
14
|
+
t.string :key, :null => false
|
15
15
|
t.text :value, :null => false
|
16
16
|
end
|
17
17
|
add_index :key_values, :key, :unique => true
|
@@ -53,7 +53,6 @@ HandlerSocket ([Ubuntu natty guide](http://grosser.it/2011/05/14/installing-mysq
|
|
53
53
|
|
54
54
|
TODO
|
55
55
|
====
|
56
|
-
- nice error handling for HandlerSocket
|
57
56
|
- HandlerSocket write support
|
58
57
|
- make test database configurable
|
59
58
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/key_value.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{key_value}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Roman Heinrich", "Michael Grosser"]
|
12
|
-
s.date = %q{2011-05-
|
12
|
+
s.date = %q{2011-05-17}
|
13
13
|
s.email = %q{michael@grosser.it}
|
14
14
|
s.files = [
|
15
15
|
"Gemfile",
|
data/lib/key_value.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'active_record'
|
2
2
|
|
3
3
|
class KeyValue < ActiveRecord::Base
|
4
|
+
class HandlerSocketError < RuntimeError; end
|
5
|
+
|
4
6
|
HS_DEFAULT_CONFIG = {:port => '9998'}
|
5
7
|
HS_INDEX = 31234 # just some high number...
|
6
8
|
VERSION = File.read( File.join(File.dirname(__FILE__),'..','VERSION') ).strip
|
@@ -19,9 +21,8 @@ class KeyValue < ActiveRecord::Base
|
|
19
21
|
def self.get(key)
|
20
22
|
if handler_socket
|
21
23
|
open_key_index
|
22
|
-
result =
|
23
|
-
|
24
|
-
YAML.load(result[0])
|
24
|
+
result = hs_find_by_key(key)
|
25
|
+
YAML.load(result) if result
|
25
26
|
else
|
26
27
|
KeyValue.find_by_key(key).try(:value)
|
27
28
|
end
|
@@ -78,6 +79,18 @@ class KeyValue < ActiveRecord::Base
|
|
78
79
|
end
|
79
80
|
|
80
81
|
def self.open_key_index
|
81
|
-
@open_key_index ||=
|
82
|
+
@open_key_index ||= begin
|
83
|
+
result = hs_connection.open_index(HS_INDEX, hs_connection_config[:database], table_name, "index_#{table_name}_on_key", 'value')
|
84
|
+
raise HandlerSocketError, result[1] if result[0] == -1
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def self.hs_find_by_key(key)
|
89
|
+
result = hs_connection.execute_single(HS_INDEX, '=', [key])
|
90
|
+
if result[0] == -1
|
91
|
+
raise HandlerSocketError, result[1]
|
92
|
+
else
|
93
|
+
result[1][0].try(:[],0)
|
94
|
+
end
|
82
95
|
end
|
83
96
|
end
|
data/spec/key_value_spec.rb
CHANGED
@@ -124,6 +124,13 @@ describe KeyValue do
|
|
124
124
|
KeyValue['xxx'].should == false
|
125
125
|
end
|
126
126
|
|
127
|
+
it "raises on hs error" do
|
128
|
+
KeyValue.hs_connection.should_receive(:execute_single).and_return [-1, 'wtf']
|
129
|
+
lambda{
|
130
|
+
KeyValue['xxx'].should == '123'
|
131
|
+
}.should raise_error('wtf')
|
132
|
+
end
|
133
|
+
|
127
134
|
it "uses defaults" do
|
128
135
|
KeyValue.send(:hs_connection_config).except(:username, :password).should == {
|
129
136
|
:flags=>2,
|
data/spec/spec_helper.rb
CHANGED
@@ -19,8 +19,8 @@ end
|
|
19
19
|
ActiveRecord::Schema.define(:version => 1) do
|
20
20
|
drop_table :key_values rescue nil
|
21
21
|
|
22
|
-
create_table :key_values
|
23
|
-
t.string :key, :null => false
|
22
|
+
create_table :key_values do |t|
|
23
|
+
t.string :key, :null => false
|
24
24
|
t.text :value, :null => false
|
25
25
|
end
|
26
26
|
add_index :key_values, :key, :unique => true
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: key_value
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 4
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Roman Heinrich
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2011-05-
|
19
|
+
date: 2011-05-17 00:00:00 +02:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|