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.
- data/lib/cockpit/core/scope.rb +5 -1
- data/lib/cockpit/core/settings.rb +17 -0
- data/lib/cockpit/stores/active_record.rb +14 -2
- metadata +4 -4
data/lib/cockpit/core/scope.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
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-
|
18
|
+
date: 2010-09-29 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|