Sutto-perennial 0.2.3.0 → 0.2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/perennial/core_ext/misc.rb +13 -0
- data/lib/perennial/settings.rb +26 -1
- data/lib/perennial.rb +1 -1
- metadata +4 -3
@@ -84,6 +84,19 @@ class Hash
|
|
84
84
|
self.each_pair { |k,v| hash[k.to_sym] = v }
|
85
85
|
replace hash
|
86
86
|
end
|
87
|
+
|
88
|
+
def stringify_keys!
|
89
|
+
hash = {}
|
90
|
+
self.each_pair { |k, v| hash[k.to_s] = v }
|
91
|
+
replace hash
|
92
|
+
end
|
93
|
+
|
94
|
+
def stringify_keys
|
95
|
+
hash = self.dup
|
96
|
+
hash.stringify_keys!
|
97
|
+
return hash
|
98
|
+
end
|
99
|
+
|
87
100
|
end
|
88
101
|
|
89
102
|
class Module
|
data/lib/perennial/settings.rb
CHANGED
@@ -48,6 +48,14 @@ module Perennial
|
|
48
48
|
setup! if setup?
|
49
49
|
end
|
50
50
|
|
51
|
+
def lookup_key_path
|
52
|
+
@@lookup_key_path ||= ["default"]
|
53
|
+
end
|
54
|
+
|
55
|
+
def lookup_key_path=(value)
|
56
|
+
@@lookup_key_path = value
|
57
|
+
end
|
58
|
+
|
51
59
|
def setup(options = {})
|
52
60
|
self.setup!(options) unless setup?
|
53
61
|
end
|
@@ -57,7 +65,7 @@ module Perennial
|
|
57
65
|
settings_file = self.default_settings_path
|
58
66
|
if File.exist?(settings_file)
|
59
67
|
loaded_yaml = YAML.load(File.read(settings_file))
|
60
|
-
@@configuration.merge!(loaded_yaml
|
68
|
+
@@configuration.merge!(lookup_settings_from(loaded_yaml))
|
61
69
|
end
|
62
70
|
@@configuration.merge! options
|
63
71
|
@@configuration.symbolize_keys!
|
@@ -68,6 +76,17 @@ module Perennial
|
|
68
76
|
@@setup = true
|
69
77
|
end
|
70
78
|
|
79
|
+
def update!(attributes = {})
|
80
|
+
return if attributes.blank?
|
81
|
+
settings_file = self.default_settings_path
|
82
|
+
settings = File.exist?(settings_file) ? YAML.load(File.read(settings_file)) : {}
|
83
|
+
namespaced_settings = lookup_settings_from(settings)
|
84
|
+
namespaced_settings.merge! attributes.stringify_keys
|
85
|
+
File.open(settings_file, "w+") { |f| f.write(settings.to_yaml) }
|
86
|
+
setup!
|
87
|
+
return true
|
88
|
+
end
|
89
|
+
|
71
90
|
def [](key)
|
72
91
|
self.setup
|
73
92
|
return self.configuration[key.to_sym]
|
@@ -98,6 +117,12 @@ module Perennial
|
|
98
117
|
end
|
99
118
|
end
|
100
119
|
|
120
|
+
def lookup_settings_from(settings_hash)
|
121
|
+
lookup_key_path.inject(settings_hash) do |h, k|
|
122
|
+
h[k.to_s] ||= {}
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
101
126
|
end
|
102
127
|
|
103
128
|
end
|
data/lib/perennial.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Sutto-perennial
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.3.
|
4
|
+
version: 0.2.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Darcy Laycock
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-09-
|
12
|
+
date: 2009-09-07 00:00:00 -07:00
|
13
13
|
default_executable: perennial
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- templates/test_helper.erb
|
68
68
|
has_rdoc: false
|
69
69
|
homepage: http://sutto.net/
|
70
|
+
licenses:
|
70
71
|
post_install_message:
|
71
72
|
rdoc_options: []
|
72
73
|
|
@@ -87,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
88
|
requirements: []
|
88
89
|
|
89
90
|
rubyforge_project:
|
90
|
-
rubygems_version: 1.
|
91
|
+
rubygems_version: 1.3.5
|
91
92
|
signing_key:
|
92
93
|
specification_version: 3
|
93
94
|
summary: A simple (generally event-oriented) application library for Ruby
|