cockpit 0.2.3 → 0.2.4

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.
@@ -8,7 +8,11 @@ module Cockpit
8
8
  end
9
9
 
10
10
  def value
11
- settings[key]
11
+ if settings[key].nil?
12
+ nil
13
+ else
14
+ JSON.parse(%Q|{"value":#{settings[key]}}|)['value']
15
+ end
12
16
  end
13
17
 
14
18
  def value=(x)
@@ -1,3 +1,4 @@
1
+ # http://refactormycode.com/codes/1204-nested-hash-from-delimiter-separated-string
1
2
  module Cockpit
2
3
  # settings have one direct definition and many child proxy
3
4
  class Settings
@@ -181,6 +182,22 @@ module Cockpit
181
182
  value.respond_to?(:empty?) ? value.empty? : !value
182
183
  end
183
184
 
185
+ def to_tree
186
+ keys.inject({}) do |result, path|
187
+ curr = result
188
+ names = path.split(".")
189
+ names.each do |name|
190
+ if name == names.last
191
+ curr[name] = Cockpit::Settings[path]
192
+ else
193
+ curr[name] ||= {}
194
+ curr = curr[name]
195
+ end
196
+ end
197
+ result
198
+ end
199
+ end
200
+
184
201
  protected
185
202
 
186
203
  def method_missing(method, *args, &block)
@@ -15,14 +15,26 @@ module Cockpit
15
15
  def setting_sum(key, conditions = {})
16
16
  conditions[:configurable_type] ||= self.sti_classes
17
17
  conditions[:key] = key
18
- Setting.sum(:value, :conditions => conditions)
18
+ if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && connection.is_a?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
19
+ select = "INTEGER"
20
+ else
21
+ select = "SIGNED"
22
+ end
23
+ select = "CAST(#{::Cockpit::AR::Setting.quoted_table_name}.value AS #{select})"
24
+ Setting.sum(:value, :conditions => conditions, :select => select)
19
25
  end
20
26
  alias setting_total setting_sum
21
27
 
22
28
  def setting_average(key, conditions = {})
23
29
  conditions[:configurable_type] ||= self.sti_classes
24
30
  conditions[:key] = key
25
- Setting.average(:value, :conditions => conditions)
31
+ if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && connection.is_a?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
32
+ select = "INTEGER"
33
+ else
34
+ select = "SIGNED"
35
+ end
36
+ select = "CAST(#{::Cockpit::AR::Setting.quoted_table_name}.value AS #{select})"
37
+ Setting.average(:value, :conditions => conditions, :select => select)
26
38
  end
27
39
  alias setting_avg setting_average
28
40
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cockpit
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 3
10
- version: 0.2.3
9
+ - 4
10
+ version: 0.2.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Lance Pollard
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-22 00:00:00 -05:00
18
+ date: 2010-09-29 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency