cockpit 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cockpit/stores/active_record.rb +29 -5
- metadata +4 -4
@@ -11,6 +11,30 @@ module Cockpit
|
|
11
11
|
base.class_eval do
|
12
12
|
has_many :settings, :as => :configurable, :class_name => "::Cockpit::AR::Setting", :dependent => :destroy
|
13
13
|
|
14
|
+
class << self
|
15
|
+
def setting_sum(key, conditions = {})
|
16
|
+
conditions[:configurable_type] ||= self.sti_classes
|
17
|
+
conditions[:key] = key
|
18
|
+
Setting.sum(:value, :conditions => conditions)
|
19
|
+
end
|
20
|
+
alias setting_total setting_sum
|
21
|
+
|
22
|
+
def setting_average(key, conditions = {})
|
23
|
+
conditions[:configurable_type] ||= self.sti_classes
|
24
|
+
conditions[:key] = key
|
25
|
+
Setting.average(:value, :conditions => conditions)
|
26
|
+
end
|
27
|
+
alias setting_avg setting_average
|
28
|
+
|
29
|
+
def method_missing(method, *args, &block)
|
30
|
+
if method.to_s =~ /(total|sum|average|avg)_(\w+)/
|
31
|
+
self.send("setting_#{$1}", $2, args.extract_options!)
|
32
|
+
else
|
33
|
+
super(method, *args, &block)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
14
38
|
unless respond_to?("get")
|
15
39
|
def get(key)
|
16
40
|
cockpit[key]
|
@@ -35,7 +59,7 @@ module Cockpit
|
|
35
59
|
end
|
36
60
|
|
37
61
|
def parsed_value
|
38
|
-
|
62
|
+
value#['root']
|
39
63
|
end
|
40
64
|
end
|
41
65
|
|
@@ -64,15 +88,15 @@ module Cockpit
|
|
64
88
|
record.save! if record && record.new_record?
|
65
89
|
|
66
90
|
setting = find_setting(key)
|
67
|
-
|
68
|
-
attributes = {:value =>
|
69
|
-
|
91
|
+
#{:value => {'root' => value}.to_json}
|
92
|
+
attributes = {:value => value.to_json}.merge(configurable_attributes)
|
70
93
|
if setting
|
71
94
|
setting.update_attributes!(attributes)
|
72
95
|
else
|
73
96
|
setting = Setting.new(attributes)
|
74
97
|
setting.key = key
|
75
98
|
record.settings << setting if record
|
99
|
+
setting[:configurable_type] = attributes[:configurable_type]
|
76
100
|
setting.save!
|
77
101
|
end
|
78
102
|
|
@@ -118,7 +142,7 @@ module Cockpit
|
|
118
142
|
def configurable_attributes
|
119
143
|
conditions = {}
|
120
144
|
if record
|
121
|
-
conditions[:configurable_type] =
|
145
|
+
conditions[:configurable_type] = record.class.name
|
122
146
|
conditions[:configurable_id] = record.id
|
123
147
|
else
|
124
148
|
conditions[:configurable_type] = nil
|
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: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
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-22 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|