amee 4.2.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ # Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
2
+ # Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
3
+
4
+ # Old-style plugin initailiser. Kept for backwards compatibility
5
+ require File.dirname(__FILE__) + "/rails/init"
data/lib/amee.rb CHANGED
@@ -4,7 +4,12 @@
4
4
  require 'rexml/document'
5
5
  require 'nokogiri'
6
6
  require 'active_support'
7
- require 'active_support/time'
7
+ begin
8
+ require 'active_support/time'
9
+ require 'active_support/array'
10
+ rescue LoadError
11
+ nil
12
+ end
8
13
  require 'log4r'
9
14
 
10
15
  # We don't NEED the JSON gem, but if it's available, use it.
@@ -59,13 +64,6 @@ require 'amee/config'
59
64
  if defined?(Rails)
60
65
  require 'amee/rails'
61
66
  ActiveRecord::Base.send :include, AMEE::Rails
62
-
63
- amee_config = "#{Rails.root}/config/amee.yml"
64
- if File.exist? amee_config
65
- $AMEE_CONFIG = AMEE::Config.setup(amee_config, Rails.env)
66
- else
67
- $AMEE_CONFIG = AMEE::Config.setup
68
- end
69
67
  end
70
68
 
71
69
  class Date
@@ -298,7 +298,8 @@ module AMEE
298
298
  def cache_key(path)
299
299
  # We have to make sure cache keys don't get too long for the filesystem,
300
300
  # so we cut them off if they're too long and add a digest for uniqueness.
301
- newpath = (path.length < 255) ? path : path.first(192)+Digest::MD5.hexdigest(path)
301
+ newpath = path.gsub(/[^0-9a-z\/]/i, '')
302
+ newpath = (newpath.length < 255) ? newpath : newpath.first(192)+Digest::MD5.hexdigest(newpath)
302
303
  (@server+newpath)
303
304
  end
304
305
 
data/lib/amee/rails.rb CHANGED
@@ -10,6 +10,14 @@ module AMEE
10
10
 
11
11
  class Connection
12
12
  def self.global(options = {})
13
+ unless defined?($AMEE_CONFIG)
14
+ amee_config = "#{::Rails.root}/config/amee.yml"
15
+ if File.exist? amee_config
16
+ $AMEE_CONFIG = AMEE::Config.setup(amee_config, ::Rails.env)
17
+ else
18
+ $AMEE_CONFIG = AMEE::Config.setup
19
+ end
20
+ end
13
21
  unless @connection
14
22
  $AMEE_CONFIG ||= {} # Make default values nil
15
23
  if $AMEE_CONFIG[:ssl] == false
@@ -37,7 +45,7 @@ module AMEE
37
45
  protected
38
46
  def self.connect(server, username, password, options)
39
47
  connection = AMEE::Connection.new(server, username, password, options)
40
- connection.authenticate
48
+ connection.authenticate unless options[:authenticate] == false
41
49
  return connection
42
50
  end
43
51
  end
@@ -56,7 +64,7 @@ module AMEE
56
64
  after_save :amee_save
57
65
  before_destroy :amee_destroy
58
66
  # Check that this object has an AMEE profile UID when saving
59
- validates :amee_profile, :presence => true
67
+ validates_presence_of :amee_profile
60
68
  end
61
69
  end
62
70
 
@@ -1,6 +1,8 @@
1
1
  # Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
2
2
  # Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
3
3
 
4
+ require 'active_support/core_ext/string'
5
+
4
6
  module AMEE
5
7
  class Connection
6
8
 
@@ -38,11 +38,11 @@ module AMEE
38
38
  <WikiDoc>#{meta.wikidoc}</WikiDoc>
39
39
  <Usages>
40
40
  EOF
41
- @usages.each_pair do |name, type|
41
+ @usages.keys.sort.each do |key|
42
42
  str += <<EOF
43
43
  <Usage>
44
- <Name>#{name}</Name>
45
- <Type>#{type.to_s.upcase}</Type>
44
+ <Name>#{key}</Name>
45
+ <Type>#{@usages[key].to_s.upcase}</Type>
46
46
  </Usage>
47
47
  EOF
48
48
  end
@@ -41,7 +41,7 @@ module AMEE
41
41
  data[:meta][:wikidoc]=x 'WikiDoc', :doc => p
42
42
  names = x('Usages/Usage/Name', :doc => p)
43
43
  types = x('Usages/Usage/Type', :doc => p)
44
- data[:meta][:usages] = names && types ? Hash[*(names.zip(types.map{|x| x.downcase.to_sym})).flatten] : {}
44
+ data[:meta][:usages] = names && types ? Hash[*([names].flatten.zip([types].flatten.map{|x| x.downcase.to_sym})).flatten] : {}
45
45
  data[:drill]=(x('DrillDown',:doc => p)=='true')
46
46
  data[:from_profile]=(x('FromProfile',:doc => p)=='true')
47
47
  data[:from_data]=(x('FromData',:doc => p)=='true')
data/rails/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ # Copyright (C) 2008-2011 AMEE UK Ltd. - http://www.amee.com
2
+ # Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
3
+
4
+ # Rails 2.3 initailiser. Kept for backwards compatibility
5
+ require 'amee'
data/spec/cache_spec.rb CHANGED
@@ -75,6 +75,11 @@ describe AMEE::Connection do
75
75
  c.expire_cache
76
76
  i = c.item :label => 'biodiesel'
77
77
  end
78
+
79
+ it "removes special characters from cache keys" do
80
+ setup_connection
81
+ @connection.send(:cache_key, "/%cache/$4/%20test").should eql 'server.example.com/cache/4/20test'
82
+ end
78
83
 
79
84
  describe 'and automatic invalidation' do
80
85
 
@@ -0,0 +1,4 @@
1
+ test:
2
+ server: stage.amee.com
3
+ username: username
4
+ password: password
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <Representation>
3
+ <ItemDefinition created="2009-04-14T12:32:50Z" modified="2011-01-26T12:28:45Z" status="ACTIVE" uid="B4DA9E4AD5F2">
4
+ <Name>Televisions Generic Ranges</Name>
5
+ <DrillDown>type,size</DrillDown>
6
+ <Usages>
7
+ <Usage present="true">
8
+ <Name>default</Name>
9
+ </Usage>
10
+ </Usages>
11
+ <Algorithms>
12
+ <Algorithm uid="7D9CA64B95CE">
13
+ <Name>default</Name>
14
+ </Algorithm>
15
+ </Algorithms>
16
+ </ItemDefinition>
17
+ <Status>OK</Status>
18
+ <Version>3.6.0</Version>
19
+ </Representation>
@@ -0,0 +1,328 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
+ <Representation>
3
+ <ItemValueDefinitions>
4
+ <ItemValueDefinition created="2009-04-14T12:32:50Z" modified="2011-01-26T12:28:47Z" status="ACTIVE" uid="FC478DA437A0">
5
+ <Name>Comment</Name>
6
+ <Path>comment</Path>
7
+ <Value/>
8
+ <WikiDoc/>
9
+ <ItemDefinition uid="B4DA9E4AD5F2">
10
+ <Name>Televisions Generic Ranges</Name>
11
+ </ItemDefinition>
12
+ <ValueDefinition uid="CCEB59CACE1B">
13
+ <Name>text</Name>
14
+ <ValueType>TEXT</ValueType>
15
+ </ValueDefinition>
16
+ <Usages>
17
+ <Usage active="true">
18
+ <Name>default</Name>
19
+ <Type>IGNORED</Type>
20
+ </Usage>
21
+ </Usages>
22
+ <Choices/>
23
+ <DrillDown>false</DrillDown>
24
+ <FromData>false</FromData>
25
+ <FromProfile>true</FromProfile>
26
+ <Versions>
27
+ <Version>
28
+ <Version>1.0</Version>
29
+ </Version>
30
+ <Version>
31
+ <Version>2.0</Version>
32
+ </Version>
33
+ </Versions>
34
+ </ItemValueDefinition>
35
+ <ItemValueDefinition created="2009-04-14T12:32:50Z" modified="2011-01-26T12:28:53Z" status="ACTIVE" uid="16C7EC3BE46F">
36
+ <Name>Hours Per Month</Name>
37
+ <Path>hoursPerMonth</Path>
38
+ <Value/>
39
+ <WikiDoc>Hours watched per month</WikiDoc>
40
+ <ItemDefinition uid="B4DA9E4AD5F2">
41
+ <Name>Televisions Generic Ranges</Name>
42
+ </ItemDefinition>
43
+ <ValueDefinition uid="45433E48B39F">
44
+ <Name>amount</Name>
45
+ <ValueType>DOUBLE</ValueType>
46
+ </ValueDefinition>
47
+ <Usages>
48
+ <Usage active="true">
49
+ <Name>default</Name>
50
+ <Type>COMPULSORY</Type>
51
+ </Usage>
52
+ </Usages>
53
+ <Choices/>
54
+ <PerUnit>month</PerUnit>
55
+ <DrillDown>false</DrillDown>
56
+ <FromData>false</FromData>
57
+ <FromProfile>true</FromProfile>
58
+ <Versions>
59
+ <Version>
60
+ <Version>1.0</Version>
61
+ </Version>
62
+ </Versions>
63
+ </ItemValueDefinition>
64
+ <ItemValueDefinition created="2009-04-14T12:32:51Z" modified="2011-01-26T12:28:49Z" status="ACTIVE" uid="B8329DD85312">
65
+ <Name>kW on</Name>
66
+ <Path>kWOn</Path>
67
+ <Value/>
68
+ <WikiDoc>Television "on" energy consumption rate </WikiDoc>
69
+ <ItemDefinition uid="B4DA9E4AD5F2">
70
+ <Name>Televisions Generic Ranges</Name>
71
+ </ItemDefinition>
72
+ <ValueDefinition uid="45433E48B39F">
73
+ <Name>amount</Name>
74
+ <ValueType>DOUBLE</ValueType>
75
+ </ValueDefinition>
76
+ <Usages/>
77
+ <Choices/>
78
+ <Unit>kW</Unit>
79
+ <DrillDown>false</DrillDown>
80
+ <FromData>true</FromData>
81
+ <FromProfile>false</FromProfile>
82
+ <Versions>
83
+ <Version>
84
+ <Version>1.0</Version>
85
+ </Version>
86
+ <Version>
87
+ <Version>2.0</Version>
88
+ </Version>
89
+ </Versions>
90
+ </ItemValueDefinition>
91
+ <ItemValueDefinition created="2009-04-14T12:32:51Z" modified="2011-01-26T12:28:48Z" status="ACTIVE" uid="D204B91C6CC1">
92
+ <Name>kW standby</Name>
93
+ <Path>kWStandby</Path>
94
+ <Value/>
95
+ <WikiDoc>Television "standby" energy consumption rate</WikiDoc>
96
+ <ItemDefinition uid="B4DA9E4AD5F2">
97
+ <Name>Televisions Generic Ranges</Name>
98
+ </ItemDefinition>
99
+ <ValueDefinition uid="45433E48B39F">
100
+ <Name>amount</Name>
101
+ <ValueType>DOUBLE</ValueType>
102
+ </ValueDefinition>
103
+ <Usages/>
104
+ <Choices/>
105
+ <Unit>kW</Unit>
106
+ <DrillDown>false</DrillDown>
107
+ <FromData>true</FromData>
108
+ <FromProfile>false</FromProfile>
109
+ <Versions>
110
+ <Version>
111
+ <Version>1.0</Version>
112
+ </Version>
113
+ <Version>
114
+ <Version>2.0</Version>
115
+ </Version>
116
+ </Versions>
117
+ </ItemValueDefinition>
118
+ <ItemValueDefinition created="2009-04-14T12:32:51Z" modified="2011-01-26T12:28:48Z" status="ACTIVE" uid="E01E927ABCCC">
119
+ <Name>Size</Name>
120
+ <Path>size</Path>
121
+ <Value/>
122
+ <WikiDoc>Television screen size (inches)</WikiDoc>
123
+ <ItemDefinition uid="B4DA9E4AD5F2">
124
+ <Name>Televisions Generic Ranges</Name>
125
+ </ItemDefinition>
126
+ <ValueDefinition uid="CCEB59CACE1B">
127
+ <Name>text</Name>
128
+ <ValueType>TEXT</ValueType>
129
+ </ValueDefinition>
130
+ <Usages/>
131
+ <Choices/>
132
+ <Unit>in</Unit>
133
+ <DrillDown>true</DrillDown>
134
+ <FromData>true</FromData>
135
+ <FromProfile>false</FromProfile>
136
+ <Versions>
137
+ <Version>
138
+ <Version>1.0</Version>
139
+ </Version>
140
+ <Version>
141
+ <Version>2.0</Version>
142
+ </Version>
143
+ </Versions>
144
+ </ItemValueDefinition>
145
+ <ItemValueDefinition created="2009-04-14T12:32:51Z" modified="2011-01-26T12:28:53Z" status="ACTIVE" uid="8C94A664A457">
146
+ <Name>Source</Name>
147
+ <Path>source</Path>
148
+ <Value/>
149
+ <WikiDoc/>
150
+ <ItemDefinition uid="B4DA9E4AD5F2">
151
+ <Name>Televisions Generic Ranges</Name>
152
+ </ItemDefinition>
153
+ <ValueDefinition uid="CCEB59CACE1B">
154
+ <Name>text</Name>
155
+ <ValueType>TEXT</ValueType>
156
+ </ValueDefinition>
157
+ <Usages/>
158
+ <Choices/>
159
+ <DrillDown>false</DrillDown>
160
+ <FromData>true</FromData>
161
+ <FromProfile>false</FromProfile>
162
+ <Versions>
163
+ <Version>
164
+ <Version>1.0</Version>
165
+ </Version>
166
+ <Version>
167
+ <Version>2.0</Version>
168
+ </Version>
169
+ </Versions>
170
+ </ItemValueDefinition>
171
+ <ItemValueDefinition created="2009-04-14T12:32:51Z" modified="2011-01-26T12:28:54Z" status="ACTIVE" uid="E2C9E1F92A34">
172
+ <Name>standby always CO2</Name>
173
+ <Path>standbyAlwaysCO2</Path>
174
+ <Value>0</Value>
175
+ <WikiDoc>Do //not// set - the algorithm will set this value.</WikiDoc>
176
+ <ItemDefinition uid="B4DA9E4AD5F2">
177
+ <Name>Televisions Generic Ranges</Name>
178
+ </ItemDefinition>
179
+ <ValueDefinition uid="45433E48B39F">
180
+ <Name>amount</Name>
181
+ <ValueType>DOUBLE</ValueType>
182
+ </ValueDefinition>
183
+ <Usages>
184
+ <Usage active="true">
185
+ <Name>default</Name>
186
+ <Type>IGNORED</Type>
187
+ </Usage>
188
+ </Usages>
189
+ <Choices/>
190
+ <Unit>kg</Unit>
191
+ <PerUnit>year</PerUnit>
192
+ <DrillDown>false</DrillDown>
193
+ <FromData>false</FromData>
194
+ <FromProfile>true</FromProfile>
195
+ <Versions>
196
+ <Version>
197
+ <Version>1.0</Version>
198
+ </Version>
199
+ <Version>
200
+ <Version>2.0</Version>
201
+ </Version>
202
+ </Versions>
203
+ </ItemValueDefinition>
204
+ <ItemValueDefinition created="2009-04-14T12:32:51Z" modified="2011-01-26T12:28:50Z" status="ACTIVE" uid="95451BD17B40">
205
+ <Name>standby mostly CO2</Name>
206
+ <Path>standbyMostlyCO2</Path>
207
+ <Value>0</Value>
208
+ <WikiDoc>Do //not// set - the algorithm will set this value.</WikiDoc>
209
+ <ItemDefinition uid="B4DA9E4AD5F2">
210
+ <Name>Televisions Generic Ranges</Name>
211
+ </ItemDefinition>
212
+ <ValueDefinition uid="45433E48B39F">
213
+ <Name>amount</Name>
214
+ <ValueType>DOUBLE</ValueType>
215
+ </ValueDefinition>
216
+ <Usages>
217
+ <Usage active="true">
218
+ <Name>default</Name>
219
+ <Type>IGNORED</Type>
220
+ </Usage>
221
+ </Usages>
222
+ <Choices/>
223
+ <Unit>kg</Unit>
224
+ <PerUnit>year</PerUnit>
225
+ <DrillDown>false</DrillDown>
226
+ <FromData>false</FromData>
227
+ <FromProfile>true</FromProfile>
228
+ <Versions>
229
+ <Version>
230
+ <Version>1.0</Version>
231
+ </Version>
232
+ <Version>
233
+ <Version>2.0</Version>
234
+ </Version>
235
+ </Versions>
236
+ </ItemValueDefinition>
237
+ <ItemValueDefinition created="2009-04-14T12:32:51Z" modified="2011-01-26T12:28:51Z" status="ACTIVE" uid="8BEF2938D789">
238
+ <Name>standby sometimes CO2</Name>
239
+ <Path>standbySometimesCO2</Path>
240
+ <Value>0</Value>
241
+ <WikiDoc>Do //not// set - the algorithm will set this value.</WikiDoc>
242
+ <ItemDefinition uid="B4DA9E4AD5F2">
243
+ <Name>Televisions Generic Ranges</Name>
244
+ </ItemDefinition>
245
+ <ValueDefinition uid="45433E48B39F">
246
+ <Name>amount</Name>
247
+ <ValueType>DOUBLE</ValueType>
248
+ </ValueDefinition>
249
+ <Usages>
250
+ <Usage active="true">
251
+ <Name>default</Name>
252
+ <Type>IGNORED</Type>
253
+ </Usage>
254
+ </Usages>
255
+ <Choices/>
256
+ <Unit>kg</Unit>
257
+ <PerUnit>year</PerUnit>
258
+ <DrillDown>false</DrillDown>
259
+ <FromData>false</FromData>
260
+ <FromProfile>true</FromProfile>
261
+ <Versions>
262
+ <Version>
263
+ <Version>1.0</Version>
264
+ </Version>
265
+ <Version>
266
+ <Version>2.0</Version>
267
+ </Version>
268
+ </Versions>
269
+ </ItemValueDefinition>
270
+ <ItemValueDefinition created="2009-04-14T12:32:52Z" modified="2011-01-26T12:28:51Z" status="ACTIVE" uid="082094F36436">
271
+ <Name>Time On</Name>
272
+ <Path>hoursOn</Path>
273
+ <Value>0</Value>
274
+ <WikiDoc>Duration television switched on</WikiDoc>
275
+ <ItemDefinition uid="B4DA9E4AD5F2">
276
+ <Name>Televisions Generic Ranges</Name>
277
+ </ItemDefinition>
278
+ <ValueDefinition uid="45433E48B39F">
279
+ <Name>amount</Name>
280
+ <ValueType>DOUBLE</ValueType>
281
+ </ValueDefinition>
282
+ <Usages>
283
+ <Usage active="true">
284
+ <Name>default</Name>
285
+ <Type>COMPULSORY</Type>
286
+ </Usage>
287
+ </Usages>
288
+ <Choices/>
289
+ <PerUnit>year</PerUnit>
290
+ <DrillDown>false</DrillDown>
291
+ <FromData>false</FromData>
292
+ <FromProfile>true</FromProfile>
293
+ <Versions>
294
+ <Version>
295
+ <Version>2.0</Version>
296
+ </Version>
297
+ </Versions>
298
+ </ItemValueDefinition>
299
+ <ItemValueDefinition created="2009-04-14T12:32:50Z" modified="2011-01-26T12:28:52Z" status="ACTIVE" uid="50971460403A">
300
+ <Name>Type</Name>
301
+ <Path>type</Path>
302
+ <Value/>
303
+ <WikiDoc>Television type</WikiDoc>
304
+ <ItemDefinition uid="B4DA9E4AD5F2">
305
+ <Name>Televisions Generic Ranges</Name>
306
+ </ItemDefinition>
307
+ <ValueDefinition uid="CCEB59CACE1B">
308
+ <Name>text</Name>
309
+ <ValueType>TEXT</ValueType>
310
+ </ValueDefinition>
311
+ <Usages/>
312
+ <Choices/>
313
+ <DrillDown>true</DrillDown>
314
+ <FromData>true</FromData>
315
+ <FromProfile>false</FromProfile>
316
+ <Versions>
317
+ <Version>
318
+ <Version>1.0</Version>
319
+ </Version>
320
+ <Version>
321
+ <Version>2.0</Version>
322
+ </Version>
323
+ </Versions>
324
+ </ItemValueDefinition>
325
+ </ItemValueDefinitions>
326
+ <Status>OK</Status>
327
+ <Version>3.6.0</Version>
328
+ </Representation>