entity_storage 1.0.4 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -1
- data/README.rdoc +2 -1
- data/Rakefile +3 -3
- data/config/database.yml +1 -1
- data/lib/entity_storage.rb +45 -40
- data/test/test_helper.rb +1 -3
- metadata +58 -16
data/History.txt
CHANGED
data/README.rdoc
CHANGED
@@ -43,8 +43,9 @@ If you access a key that doesn't exist, and is specified in default list, will b
|
|
43
43
|
Keys can be up to 512 characters in length. Values can be practically any size, and consist of any object. Objects are marshalled back and forth between database.
|
44
44
|
|
45
45
|
== REQUIREMENTS:
|
46
|
+
As of 1.0.5, requires ActiveRecord 3.0.0.beta4 or greater.
|
46
47
|
|
47
|
-
|
48
|
+
Version up to 1.0.4 requires Ruby 1.8.7 and ActiveRecord 2.2.3 or above (probably works with earlier versions, but has not been tested.)
|
48
49
|
|
49
50
|
== INSTALL:
|
50
51
|
To install from github:
|
data/Rakefile
CHANGED
@@ -10,11 +10,11 @@ Hoe.plugin :newgem
|
|
10
10
|
|
11
11
|
# Generate all the Rake tasks
|
12
12
|
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
-
$hoe = Hoe.spec '
|
13
|
+
$hoe = Hoe.spec 'entity-storage' do
|
14
14
|
self.developer 'Joshua Siler', 'joshua.siler@gmail.com'
|
15
15
|
# self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
16
|
-
self.rubyforge_name = self.name # TODO this is default value
|
17
|
-
self.extra_deps = [['activerecord','>=
|
16
|
+
self.rubyforge_name = 'entity-storage' #self.name # TODO this is default value
|
17
|
+
self.extra_deps = [['activerecord','>= 3.0.3']]
|
18
18
|
end
|
19
19
|
|
20
20
|
require 'newgem/tasks'
|
data/config/database.yml
CHANGED
data/lib/entity_storage.rb
CHANGED
@@ -1,50 +1,54 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
-
|
3
|
+
|
4
4
|
require 'rubygems'
|
5
|
-
|
5
|
+
# wtf? rails 3 active_record migrations don't work without some unspecified thing in all of rails. lame
|
6
|
+
require 'rails'
|
7
|
+
|
8
|
+
require 'active_record'
|
9
|
+
|
6
10
|
|
7
11
|
module EntityStorage
|
8
|
-
VERSION = '
|
9
|
-
|
12
|
+
VERSION = '2.0.0'
|
13
|
+
|
10
14
|
class Storage
|
11
15
|
attr_accessor :defaults
|
12
|
-
|
16
|
+
|
13
17
|
# Checks for the existence of the necessary Entities table... if not here, creates it.
|
14
18
|
def initialize(defaults={})
|
15
19
|
unless ActiveRecord::Base.connection.table_exists?('entity_storage')
|
16
|
-
AddEntitiesTable.
|
20
|
+
AddEntitiesTable.create
|
17
21
|
end
|
18
22
|
|
19
23
|
self.defaults = defaults
|
20
24
|
end
|
21
|
-
|
25
|
+
|
22
26
|
# Read a value.
|
23
27
|
def [](index)
|
24
28
|
Entity.get_value(index,@defaults[index.to_s])
|
25
29
|
end
|
26
|
-
|
30
|
+
|
27
31
|
# Write a value.
|
28
32
|
def []=(index,value)
|
29
33
|
Entity.set_value(index,value)
|
30
34
|
end
|
31
|
-
|
35
|
+
|
32
36
|
# Deletes a key and associated data from store.
|
33
37
|
def delete(index)
|
34
38
|
Entity.remove_item(index)
|
35
39
|
end
|
36
|
-
|
40
|
+
|
37
41
|
# Returns the default value of a key contained in DEFAULT_KEYS global constant.
|
38
42
|
# Does not change the stored value. Use default! to reset the value.
|
39
43
|
def default(index)
|
40
44
|
@defaults[index.to_s]
|
41
45
|
end
|
42
|
-
|
46
|
+
|
43
47
|
# Resets the default value of a key contained in DEFAULT_KEYS global constant and returns the value.
|
44
48
|
def default!(index)
|
45
49
|
Entity.reset_value(index,@defaults[index.to_s])
|
46
50
|
end
|
47
|
-
|
51
|
+
|
48
52
|
# Allows EntityStorage[:whatever] to be accessed via EntityStorage.whatever.
|
49
53
|
def method_missing(*args)
|
50
54
|
if args.length == 1
|
@@ -56,35 +60,37 @@ module EntityStorage
|
|
56
60
|
end
|
57
61
|
end
|
58
62
|
end
|
59
|
-
|
63
|
+
|
60
64
|
# This migration is required for EntityStorage to work correctly
|
61
65
|
class AddEntitiesTable < ActiveRecord::Migration
|
62
|
-
|
66
|
+
# up and down functions call broken code in Rail3 migrations gem, called it 'create'
|
67
|
+
|
68
|
+
def self.create
|
63
69
|
create_table "entity_storage", :force => true do |t|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
70
|
+
t.string "key", :limit => 512, :null => false
|
71
|
+
t.text "value"
|
72
|
+
t.datetime "created_at"
|
73
|
+
t.datetime "updated_at"
|
68
74
|
end
|
69
|
-
|
75
|
+
|
70
76
|
add_index "entity_storage", ["created_at"], :name => "created_at"
|
71
77
|
add_index "entity_storage", ["key"], :name => "key"
|
72
78
|
add_index "entity_storage", ["updated_at"], :name => "updated_at"
|
73
79
|
end
|
74
|
-
|
75
|
-
def self.down
|
76
|
-
|
77
|
-
end
|
80
|
+
|
81
|
+
#def self.down
|
82
|
+
# drop_table :entities
|
83
|
+
#end
|
78
84
|
end
|
79
|
-
|
80
|
-
|
85
|
+
|
86
|
+
|
81
87
|
class Entity < ActiveRecord::Base
|
82
88
|
set_table_name "entity_storage"
|
83
|
-
|
89
|
+
|
84
90
|
# Entities should be used via class methods and not instantiated directly.
|
85
91
|
private_class_method :new
|
86
|
-
|
87
|
-
# Gets value based on specific key
|
92
|
+
|
93
|
+
# Gets value based on specific key.`
|
88
94
|
# If not found, will initialize according to defaults set in DEFAULT_KEYS global constant.
|
89
95
|
def self.get_value(search_key,default_value)
|
90
96
|
e = Entity.find_by_key(search_key.to_s)
|
@@ -93,8 +99,8 @@ module EntityStorage
|
|
93
99
|
end
|
94
100
|
e.value rescue nil
|
95
101
|
end
|
96
|
-
|
97
|
-
# Sets value for a specific key. If key doesn't exist, creates with value.
|
102
|
+
|
103
|
+
# Sets value for a specific key. If key doesn't exist, creates with value.
|
98
104
|
def self.set_value(search_key, new_value)
|
99
105
|
e = Entity.find_by_key(search_key.to_s)
|
100
106
|
if e.nil?
|
@@ -104,33 +110,33 @@ module EntityStorage
|
|
104
110
|
e.value = new_value
|
105
111
|
e.save
|
106
112
|
end
|
107
|
-
|
113
|
+
|
108
114
|
# Resets a key contained in DEFAULT_KEYS global constant to it's default value
|
109
115
|
def self.reset_value(search_key,default_value)
|
110
116
|
Entity.remove_item(search_key)
|
111
|
-
initialize_value(search_key,default_value).value
|
117
|
+
initialize_value(search_key,default_value).value
|
112
118
|
end
|
113
|
-
|
119
|
+
|
114
120
|
# Deletes a record from key store.
|
115
121
|
def self.remove_item(search_key)
|
116
122
|
e = Entity.find_by_key(search_key.to_s)
|
117
123
|
e.destroy rescue 0
|
118
124
|
end
|
119
|
-
|
125
|
+
|
120
126
|
def value=(data)
|
121
127
|
write_attribute(:value,Marshal.dump(data))
|
122
128
|
end
|
123
|
-
|
129
|
+
|
124
130
|
def value
|
125
131
|
Marshal.load(read_attribute(:value))
|
126
132
|
end
|
127
|
-
|
133
|
+
|
128
134
|
def key=(newkey)
|
129
135
|
write_attribute(:key,newkey.to_s)
|
130
136
|
end
|
131
|
-
|
137
|
+
|
132
138
|
private
|
133
|
-
|
139
|
+
|
134
140
|
# Checks provided key against internal defaults list and initializes to default value.
|
135
141
|
# Defaults defined in DEFAULT_KEYS global constant.
|
136
142
|
def self.initialize_value(search_key,default_value)
|
@@ -140,8 +146,7 @@ module EntityStorage
|
|
140
146
|
en.save
|
141
147
|
en
|
142
148
|
end
|
143
|
-
|
149
|
+
|
144
150
|
end
|
145
151
|
|
146
152
|
end
|
147
|
-
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: entity_storage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 15
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 2.0.0
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Joshua Siler
|
@@ -9,29 +15,57 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-12-10 00:00:00 -08:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
|
-
name:
|
22
|
+
name: rails
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 1
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
- 3
|
34
|
+
version: 3.0.3
|
17
35
|
type: :runtime
|
18
|
-
|
19
|
-
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: activerecord
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
20
42
|
requirements:
|
21
43
|
- - ">="
|
22
44
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
45
|
+
hash: 1
|
46
|
+
segments:
|
47
|
+
- 3
|
48
|
+
- 0
|
49
|
+
- 3
|
50
|
+
version: 3.0.3
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
25
53
|
- !ruby/object:Gem::Dependency
|
26
54
|
name: hoe
|
27
|
-
|
28
|
-
|
29
|
-
|
55
|
+
prerelease: false
|
56
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
30
58
|
requirements:
|
31
59
|
- - ">="
|
32
60
|
- !ruby/object:Gem::Version
|
61
|
+
hash: 5
|
62
|
+
segments:
|
63
|
+
- 2
|
64
|
+
- 3
|
65
|
+
- 3
|
33
66
|
version: 2.3.3
|
34
|
-
|
67
|
+
type: :development
|
68
|
+
version_requirements: *id003
|
35
69
|
description: |-
|
36
70
|
An easy to use Key/Value store for any Ruby on Rails project. Like Memcache, only persistent. Stores config values & application wide state in the database in order to survive server restarts.
|
37
71
|
|
@@ -70,21 +104,29 @@ rdoc_options:
|
|
70
104
|
require_paths:
|
71
105
|
- lib
|
72
106
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
73
108
|
requirements:
|
74
109
|
- - ">="
|
75
110
|
- !ruby/object:Gem::Version
|
76
|
-
|
77
|
-
|
111
|
+
hash: 57
|
112
|
+
segments:
|
113
|
+
- 1
|
114
|
+
- 8
|
115
|
+
- 7
|
116
|
+
version: 1.8.7
|
78
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
none: false
|
79
119
|
requirements:
|
80
120
|
- - ">="
|
81
121
|
- !ruby/object:Gem::Version
|
122
|
+
hash: 3
|
123
|
+
segments:
|
124
|
+
- 0
|
82
125
|
version: "0"
|
83
|
-
version:
|
84
126
|
requirements: []
|
85
127
|
|
86
|
-
rubyforge_project:
|
87
|
-
rubygems_version: 1.3.
|
128
|
+
rubyforge_project: entity-storage
|
129
|
+
rubygems_version: 1.3.7
|
88
130
|
signing_key:
|
89
131
|
specification_version: 3
|
90
132
|
summary: An easy to use Key/Value store for any Ruby on Rails project
|