kvc 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +13 -1
- data/lib/kvc.rb +18 -16
- data/lib/kvc/settings.rb +2 -4
- data/test/kvc_test.rb +1 -1
- metadata +10 -6
data/History.txt
CHANGED
@@ -1,6 +1,18 @@
|
|
1
|
+
=== 0.0.3 / 2009-06-27
|
2
|
+
|
3
|
+
* 1 minor enhancement
|
4
|
+
|
5
|
+
* Optimize by relying less on method_missing.
|
6
|
+
|
7
|
+
|
8
|
+
* 1 bugfix
|
9
|
+
|
10
|
+
* Don't confuse strings and symbols.
|
11
|
+
|
12
|
+
|
1
13
|
=== 0.0.2 / 2009-04-04
|
2
14
|
|
3
|
-
* 1 minor
|
15
|
+
* 1 minor enhancement
|
4
16
|
|
5
17
|
* Move KVC::Settings under "lib" to meet gem expectations.
|
6
18
|
|
data/lib/kvc.rb
CHANGED
@@ -35,30 +35,32 @@
|
|
35
35
|
#
|
36
36
|
# Failed validations will raise <tt>ActiveRecord::RecordInvalid</tt>.
|
37
37
|
module KVC
|
38
|
-
VERSION = "0.0.
|
38
|
+
VERSION = "0.0.3"
|
39
39
|
|
40
40
|
class << self
|
41
|
+
def [](key)
|
42
|
+
if setting = KVC::Settings.find_by_key(key.to_s)
|
43
|
+
KVC::SettingsProxy.new setting
|
44
|
+
elsif KVC::Settings.strict_keys?
|
45
|
+
raise NoMethodError,
|
46
|
+
"undefined method `#{key}' for #{self}:#{self.class}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def []=(key, value)
|
51
|
+
setting = KVC::Settings.find_or_initialize_by_key key.to_s
|
52
|
+
setting.update_attributes! :value => value
|
53
|
+
end
|
54
|
+
|
41
55
|
private
|
42
56
|
|
43
57
|
# Handles the key-value magic.
|
44
58
|
def method_missing(method, *args, &block)
|
45
59
|
key = method.to_s
|
46
|
-
key.sub!(/^\[\](=?)$/) { "#{args.shift}#{$1}" }
|
47
|
-
|
48
60
|
if key.sub!(/=$/) {} # Is it a writer method?
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
53
|
-
elsif setting = KVC::Settings.find_by_key(key) # Is it a reader?
|
54
|
-
if args.present?
|
55
|
-
error_message = "wrong number of arguments (#{args.length} for 0)"
|
56
|
-
raise ArgumentError, error_message
|
57
|
-
end
|
58
|
-
|
59
|
-
KVC::SettingsProxy.new(setting)
|
60
|
-
elsif args.present? || KVC::Settings.strict_keys?
|
61
|
-
raise NoMethodError
|
61
|
+
self[key] = *args
|
62
|
+
else
|
63
|
+
self[key, *args]
|
62
64
|
end
|
63
65
|
end
|
64
66
|
end
|
data/lib/kvc/settings.rb
CHANGED
@@ -43,14 +43,12 @@ class KVC::Settings < ActiveRecord::Base
|
|
43
43
|
|
44
44
|
# Deserializes value from database.
|
45
45
|
def value
|
46
|
-
@value ||= YAML.load
|
46
|
+
@value ||= YAML.load read_attribute(:value)
|
47
47
|
end
|
48
48
|
|
49
49
|
# Serializes value for database.
|
50
50
|
def value=(input)
|
51
|
-
|
52
|
-
write_attribute :value, input.to_yaml
|
53
|
-
end
|
51
|
+
write_attribute :value, (@value = input).to_yaml
|
54
52
|
end
|
55
53
|
|
56
54
|
private
|
data/test/kvc_test.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kvc
|
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
|
- Stephen Celis
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-06-27 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -20,9 +20,11 @@ dependencies:
|
|
20
20
|
requirements:
|
21
21
|
- - ">="
|
22
22
|
- !ruby/object:Gem::Version
|
23
|
-
version:
|
23
|
+
version: 2.0.0
|
24
24
|
version:
|
25
|
-
description:
|
25
|
+
description: |-
|
26
|
+
KVC (Key-Value Configuration) provides a powerful, transparent way to maintain
|
27
|
+
mutable app settings in the database.
|
26
28
|
email:
|
27
29
|
- stephen@stephencelis.com
|
28
30
|
executables: []
|
@@ -46,6 +48,8 @@ files:
|
|
46
48
|
- uninstall.rb
|
47
49
|
has_rdoc: true
|
48
50
|
homepage: http://github.com/stephencelis/kvc
|
51
|
+
licenses: []
|
52
|
+
|
49
53
|
post_install_message:
|
50
54
|
rdoc_options:
|
51
55
|
- --main
|
@@ -67,9 +71,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
71
|
requirements: []
|
68
72
|
|
69
73
|
rubyforge_project: kvc
|
70
|
-
rubygems_version: 1.3.
|
74
|
+
rubygems_version: 1.3.5
|
71
75
|
signing_key:
|
72
|
-
specification_version:
|
76
|
+
specification_version: 3
|
73
77
|
summary: KVC (Key-Value Configuration) provides a powerful, transparent way to maintain mutable app settings in the database.
|
74
78
|
test_files: []
|
75
79
|
|