amee-data-abstraction 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "amee", "~> 4.0"
3
+ gem "amee", "~> 4.1.5"
4
4
  gem 'uuidtools', '2.1.2'
5
5
  gem 'quantify', '~> 2.0.0'
6
6
 
data/Gemfile.lock CHANGED
@@ -2,11 +2,11 @@ GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
4
  activesupport (3.0.10)
5
- amee (4.0.0)
5
+ amee (4.1.5)
6
6
  activesupport (~> 3.0.10)
7
7
  json
8
8
  log4r
9
- nokogiri (~> 1.4.3.1)
9
+ nokogiri (~> 1.4.4)
10
10
  builder (3.0.0)
11
11
  diff-lcs (1.1.3)
12
12
  flexmock (0.9.0)
@@ -16,9 +16,9 @@ GEM
16
16
  bundler (~> 1.0)
17
17
  git (>= 1.2.5)
18
18
  rake
19
- json (1.5.4)
19
+ json (1.6.1)
20
20
  log4r (1.1.9)
21
- nokogiri (1.4.3.1)
21
+ nokogiri (1.4.7)
22
22
  quantify (2.0.0)
23
23
  activesupport (~> 3.0.10)
24
24
  i18n
@@ -39,7 +39,7 @@ PLATFORMS
39
39
  ruby
40
40
 
41
41
  DEPENDENCIES
42
- amee (~> 4.0)
42
+ amee (~> 4.1.5)
43
43
  builder
44
44
  bundler (~> 1.0.0)
45
45
  flexmock (> 0.8.6)
data/README.txt CHANGED
@@ -166,8 +166,8 @@ From this global calculation set, initialize a new calculation
166
166
 
167
167
  The AMEE::DataAbstraction module uses the 'amee' ruby gem to interact with AMEE.
168
168
  The standard method for configuring and instantiating a connection to the AMEE
169
- API is to provide authentication credentials in the /config/amee.yml file,
170
- structured thus:
169
+ API is to provide authentication credentials in the /config/amee.yml file. It is
170
+ recommended to use one of the caching options in order to reduce API calls:
171
171
 
172
172
  ---
173
173
  production:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.0
1
+ 2.1.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{amee-data-abstraction}
8
- s.version = "2.1.0"
8
+ s.version = "2.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["James Hetherington", "Andrew Berkeley", "James Smith", "George Palmer"]
12
- s.date = %q{2011-10-10}
12
+ s.date = %q{2011-10-12}
13
13
  s.description = %q{Part of the AMEEappkit this gem provides a data abstraction layer, decreasing the amount and detail of development required}
14
14
  s.email = %q{help@amee.com}
15
15
  s.extra_rdoc_files = [
@@ -71,14 +71,14 @@ Gem::Specification.new do |s|
71
71
  s.homepage = %q{http://github.com/AMEE/amee-data-abstraction}
72
72
  s.licenses = ["BSD 3-Clause"]
73
73
  s.require_paths = ["lib"]
74
- s.rubygems_version = %q{1.5.3}
74
+ s.rubygems_version = %q{1.4.2}
75
75
  s.summary = %q{Calculation and form building tool hiding details of AMEEconnect}
76
76
 
77
77
  if s.respond_to? :specification_version then
78
78
  s.specification_version = 3
79
79
 
80
80
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
81
- s.add_runtime_dependency(%q<amee>, ["~> 4.0"])
81
+ s.add_runtime_dependency(%q<amee>, ["~> 4.1.5"])
82
82
  s.add_runtime_dependency(%q<uuidtools>, ["= 2.1.2"])
83
83
  s.add_runtime_dependency(%q<quantify>, ["~> 2.0.0"])
84
84
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -88,7 +88,7 @@ Gem::Specification.new do |s|
88
88
  s.add_development_dependency(%q<rcov>, [">= 0"])
89
89
  s.add_development_dependency(%q<rdoc>, [">= 0"])
90
90
  else
91
- s.add_dependency(%q<amee>, ["~> 4.0"])
91
+ s.add_dependency(%q<amee>, ["~> 4.1.5"])
92
92
  s.add_dependency(%q<uuidtools>, ["= 2.1.2"])
93
93
  s.add_dependency(%q<quantify>, ["~> 2.0.0"])
94
94
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -99,7 +99,7 @@ Gem::Specification.new do |s|
99
99
  s.add_dependency(%q<rdoc>, [">= 0"])
100
100
  end
101
101
  else
102
- s.add_dependency(%q<amee>, ["~> 4.0"])
102
+ s.add_dependency(%q<amee>, ["~> 4.1.5"])
103
103
  s.add_dependency(%q<uuidtools>, ["= 2.1.2"])
104
104
  s.add_dependency(%q<quantify>, ["~> 2.0.0"])
105
105
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
@@ -42,8 +42,14 @@ module AMEE
42
42
  def choices(*args)
43
43
  if args.empty?
44
44
  if @choices.blank?
45
- c=parent.amee_drill(:before=>label).choices
46
- c.length==1 ? [value] : c
45
+ drill_down = parent.amee_drill(:before=>label)
46
+ if single_choice = drill_down.selections[path]
47
+ disable!
48
+ [single_choice]
49
+ else
50
+ enable!
51
+ drill_down.choices
52
+ end
47
53
  else
48
54
  @choices
49
55
  end
@@ -11,6 +11,8 @@ module AMEE
11
11
  #
12
12
  class Input < Term
13
13
 
14
+ attr_accessor :dirty
15
+
14
16
  # Returns the valid choices for this input
15
17
  # (Abstract, implemented only for subclasses of input.)
16
18
  def choices
@@ -29,6 +31,7 @@ module AMEE
29
31
  @validation = nil
30
32
  validation_message {"#{name} is invalid."}
31
33
  super
34
+ @dirty = false
32
35
  end
33
36
 
34
37
  # Configures the value of <tt>self</tt> to be fixed to <tt>val</tt>, i.e.
@@ -66,7 +69,7 @@ module AMEE
66
69
  unless args.empty?
67
70
  if args.first.to_s != @value.to_s
68
71
  raise Exceptions::FixedValueInterference if fixed?
69
- parent.dirty! if parent and parent.is_a? OngoingCalculation
72
+ mark_as_dirty
70
73
  end
71
74
  end
72
75
  super
@@ -184,6 +187,10 @@ module AMEE
184
187
  def disabled?
185
188
  super || fixed?
186
189
  end
190
+
191
+ def dirty?
192
+ @dirty
193
+ end
187
194
 
188
195
  protected
189
196
  # Returns <tt>true</tt> if the value set for <tt>self</tt> is either blank
@@ -192,6 +199,11 @@ module AMEE
192
199
  def valid?
193
200
  validation.blank? || validation === @value_before_cast
194
201
  end
202
+
203
+ def mark_as_dirty
204
+ @dirty = true
205
+ parent.dirty! if parent and parent.is_a? OngoingCalculation
206
+ end
195
207
  end
196
208
  end
197
209
  end
@@ -235,6 +235,10 @@ module AMEE
235
235
  reset_invalidity_messages
236
236
  end
237
237
 
238
+ def clear_outputs
239
+ outputs.each {|output| output.value nil }
240
+ end
241
+
238
242
  def ==(other_calc)
239
243
  !terms.inject(false) do |boolean,term|
240
244
  boolean || term != other_calc[term.label]
@@ -283,7 +287,7 @@ module AMEE
283
287
  # and units for any unset <i>Profile</i> terms (profile item values) from
284
288
  # the AMEE platform
285
289
  #
286
- def load_profile_item_values
290
+ def load_profile_item_values
287
291
  return unless profile_item
288
292
  profiles.unset.each do |term|
289
293
  ameeval=profile_item.values.find { |value| value[:path] == term.path }
@@ -305,6 +309,7 @@ module AMEE
305
309
  def load_drills
306
310
  return unless profile_item
307
311
  drills.each do |term|
312
+ next unless term.value.nil? || term.dirty?
308
313
  ameeval=data_item.value(term.path)
309
314
  raise Exceptions::Syncronization if term.set? && ameeval!=term.value
310
315
  term.value ameeval
@@ -325,6 +330,7 @@ module AMEE
325
330
  load_drills
326
331
  rescue Exceptions::Syncronization
327
332
  delete_profile_item
333
+ clear_outputs
328
334
  end
329
335
  load_metadata
330
336
  # We could create an unsatisfied PI, and just check drilled? here
@@ -451,10 +457,8 @@ module AMEE
451
457
  # <i>Profile</i> term values and attributes
452
458
  #
453
459
  def set_profile_item_values
454
- AMEE::Profile::Item.update(connection,profile_item_path,
455
- profile_options.merge(:get_item=>false))
456
- #Clear the memoised profile item, to reload with updated values
457
- @profile_item=nil
460
+ @profile_item = AMEE::Profile::Item.update(connection,profile_item_path,
461
+ profile_options.merge(:get_item=>true))
458
462
  end
459
463
 
460
464
  # Delete the profile item which is associated with <tt>self</tt> from the
@@ -463,7 +467,7 @@ module AMEE
463
467
  #
464
468
  def delete_profile_item
465
469
  AMEE::Profile::Item.delete(connection,profile_item_path)
466
- self.profile_item_uid=false
470
+ self.profile_item_uid=nil
467
471
  @profile_item=nil
468
472
  end
469
473
 
@@ -509,6 +513,8 @@ module AMEE
509
513
  @profile_category||=AMEE::Profile::Category.get(connection, profile_category_path)
510
514
  end
511
515
 
516
+ public
517
+
512
518
  # Automatically set the value of a drill term if there is only one choice
513
519
  def autodrill
514
520
 
@@ -529,8 +535,6 @@ module AMEE
529
535
  end
530
536
  end
531
537
 
532
- public
533
-
534
538
  # Instantiate an <tt>AMEE::Data::DrillDown</tt> object representing the
535
539
  # drill down sequence defined by the drill terms associated with
536
540
  # <tt>self</tt>. As with <tt>#drill_options</tt>, An optional hash argument
@@ -1,11 +1,13 @@
1
1
  require File.dirname(File.dirname(__FILE__)) + '/spec_helper.rb'
2
2
  describe Drill do
3
+
3
4
  it 'knows its options when it is the first choice' do
4
5
  AMEEMocker.new(self,:path=>'transport/car/generic',
5
6
  :selections=>[],
6
7
  :choices=>['diesel','petrol']).drill
7
8
  Transport.begin_calculation[:fuel].send(:choices).should eql ['diesel','petrol']
8
9
  end
10
+
9
11
  it 'knows its options when it is a later choice' do
10
12
  AMEEMocker.new(self,:path=>'transport/car/generic',
11
13
  :selections=>[['fuel','diesel']],
@@ -14,6 +16,7 @@ describe Drill do
14
16
  t[:fuel].value 'diesel'
15
17
  t[:size].send(:choices).should eql ['large','small']
16
18
  end
19
+
17
20
  it 'is enabled iff it is the next choice or has been chosen' do
18
21
  t=Transport.begin_calculation
19
22
  t[:fuel].enabled?.should be_true
@@ -25,6 +28,7 @@ describe Drill do
25
28
  t[:fuel].enabled?.should be_true
26
29
  t[:size].enabled?.should be_true
27
30
  end
31
+
28
32
  it 'is valid iff assigned a choice in the choices' do
29
33
  AMEEMocker.new(self,:path=>'transport/car/generic',
30
34
  :selections=>[],
@@ -35,4 +39,21 @@ describe Drill do
35
39
  t[:fuel].value 'banana'
36
40
  t[:fuel].send(:valid?).should be_false
37
41
  end
42
+
43
+ it "should set and get custom choices" do
44
+ t=Transport.begin_calculation
45
+ t[:fuel].choices 'anthracite', 'lignite'
46
+ t[:fuel].choices.should eql ['anthracite', 'lignite']
47
+ end
48
+
49
+ it 'is sets correct single choice if AMEE skips during drill' do
50
+ mocker = AMEEMocker.new(self,:path=>'transport/car/generic',
51
+ :selections=>[['fuel','diesel']])
52
+ mocker.drill_with_skip('size'=>'small')
53
+ t=Transport.begin_calculation
54
+ t[:fuel].value 'diesel'
55
+ t[:fuel].should_not be_disabled
56
+ t[:size].choices.should eql ['small']
57
+ t[:size].should be_disabled
58
+ end
38
59
  end
@@ -24,6 +24,14 @@ describe OngoingCalculation do
24
24
  d.outputs.set.labels.should eql [:co2]
25
25
  d.outputs.unset.labels.should eql []
26
26
  end
27
+ it 'can clear outputs' do
28
+ d=Electricity.begin_calculation
29
+ d.outputs.unset.labels.should eql [:co2]
30
+ d[:co2].value 5
31
+ d[:co2].value.should eql 5
32
+ d.clear_outputs
33
+ d[:co2].value.should be_nil
34
+ end
27
35
  it 'can have values chosen' do
28
36
  AMEEMocker.new(self,:path=>'business/energy/electricity/grid',
29
37
  :selections=>[['country','argentina']],
data/spec/spec_helper.rb CHANGED
@@ -77,6 +77,21 @@ class AMEEMocker
77
77
  return self
78
78
  end
79
79
 
80
+ # This represents the skipping of drill choices which occur on an AMEE drill
81
+ # down when only one choice exists for a given drill - it skips to the next,
82
+ # offering the next set of choices or a uid. In these cases, the skipped drill
83
+ # is set as an automatic selection
84
+ def drill_with_skip(skipped_selections=[])
85
+ test.flexmock(AMEE::Data::DrillDown).
86
+ should_receive(:get).
87
+ with(connection,
88
+ "/data/#{path}/drill?#{selections.map{|k,v|"#{k}=#{v}"}.join('&')}").
89
+ at_least.once.
90
+ and_return(test.flexmock(:choices=>choices,:selections=>Hash[selections].merge(skipped_selections),
91
+ :data_item_uid=>dataitemuid))
92
+ return self
93
+ end
94
+
80
95
  def profile_list
81
96
  test.flexmock(AMEE::Profile::ProfileList).should_receive(:new).
82
97
  with(connection).at_least.once.
@@ -247,7 +262,7 @@ class AMEEMocker
247
262
  def update
248
263
  test.flexmock(AMEE::Profile::Item).should_receive(:update).
249
264
  with(connection,pipath,
250
- {:get_item=>false}.merge(existing).merge(params)).
265
+ {:get_item=>true}.merge(existing).merge(params)).
251
266
  at_least.once
252
267
  return self
253
268
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amee-data-abstraction
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 1
9
- - 0
10
- version: 2.1.0
9
+ - 1
10
+ version: 2.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Hetherington
@@ -18,26 +18,29 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2011-10-10 00:00:00 +01:00
21
+ date: 2011-10-12 00:00:00 +01:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
25
+ prerelease: false
25
26
  name: amee
27
+ type: :runtime
26
28
  version_requirements: &id001 !ruby/object:Gem::Requirement
27
29
  none: false
28
30
  requirements:
29
31
  - - ~>
30
32
  - !ruby/object:Gem::Version
31
- hash: 27
33
+ hash: 49
32
34
  segments:
33
35
  - 4
34
- - 0
35
- version: "4.0"
36
- prerelease: false
37
- type: :runtime
36
+ - 1
37
+ - 5
38
+ version: 4.1.5
38
39
  requirement: *id001
39
40
  - !ruby/object:Gem::Dependency
41
+ prerelease: false
40
42
  name: uuidtools
43
+ type: :runtime
41
44
  version_requirements: &id002 !ruby/object:Gem::Requirement
42
45
  none: false
43
46
  requirements:
@@ -49,11 +52,11 @@ dependencies:
49
52
  - 1
50
53
  - 2
51
54
  version: 2.1.2
52
- prerelease: false
53
- type: :runtime
54
55
  requirement: *id002
55
56
  - !ruby/object:Gem::Dependency
57
+ prerelease: false
56
58
  name: quantify
59
+ type: :runtime
57
60
  version_requirements: &id003 !ruby/object:Gem::Requirement
58
61
  none: false
59
62
  requirements:
@@ -65,11 +68,11 @@ dependencies:
65
68
  - 0
66
69
  - 0
67
70
  version: 2.0.0
68
- prerelease: false
69
- type: :runtime
70
71
  requirement: *id003
71
72
  - !ruby/object:Gem::Dependency
73
+ prerelease: false
72
74
  name: bundler
75
+ type: :development
73
76
  version_requirements: &id004 !ruby/object:Gem::Requirement
74
77
  none: false
75
78
  requirements:
@@ -81,11 +84,11 @@ dependencies:
81
84
  - 0
82
85
  - 0
83
86
  version: 1.0.0
84
- prerelease: false
85
- type: :development
86
87
  requirement: *id004
87
88
  - !ruby/object:Gem::Dependency
89
+ prerelease: false
88
90
  name: jeweler
91
+ type: :development
89
92
  version_requirements: &id005 !ruby/object:Gem::Requirement
90
93
  none: false
91
94
  requirements:
@@ -97,11 +100,11 @@ dependencies:
97
100
  - 6
98
101
  - 4
99
102
  version: 1.6.4
100
- prerelease: false
101
- type: :development
102
103
  requirement: *id005
103
104
  - !ruby/object:Gem::Dependency
105
+ prerelease: false
104
106
  name: rspec
107
+ type: :development
105
108
  version_requirements: &id006 !ruby/object:Gem::Requirement
106
109
  none: false
107
110
  requirements:
@@ -113,11 +116,11 @@ dependencies:
113
116
  - 6
114
117
  - 0
115
118
  version: 2.6.0
116
- prerelease: false
117
- type: :development
118
119
  requirement: *id006
119
120
  - !ruby/object:Gem::Dependency
121
+ prerelease: false
120
122
  name: flexmock
123
+ type: :development
121
124
  version_requirements: &id007 !ruby/object:Gem::Requirement
122
125
  none: false
123
126
  requirements:
@@ -129,11 +132,11 @@ dependencies:
129
132
  - 8
130
133
  - 6
131
134
  version: 0.8.6
132
- prerelease: false
133
- type: :development
134
135
  requirement: *id007
135
136
  - !ruby/object:Gem::Dependency
137
+ prerelease: false
136
138
  name: rcov
139
+ type: :development
137
140
  version_requirements: &id008 !ruby/object:Gem::Requirement
138
141
  none: false
139
142
  requirements:
@@ -143,11 +146,11 @@ dependencies:
143
146
  segments:
144
147
  - 0
145
148
  version: "0"
146
- prerelease: false
147
- type: :development
148
149
  requirement: *id008
149
150
  - !ruby/object:Gem::Dependency
151
+ prerelease: false
150
152
  name: rdoc
153
+ type: :development
151
154
  version_requirements: &id009 !ruby/object:Gem::Requirement
152
155
  none: false
153
156
  requirements:
@@ -157,8 +160,6 @@ dependencies:
157
160
  segments:
158
161
  - 0
159
162
  version: "0"
160
- prerelease: false
161
- type: :development
162
163
  requirement: *id009
163
164
  description: Part of the AMEEappkit this gem provides a data abstraction layer, decreasing the amount and detail of development required
164
165
  email: help@amee.com
@@ -250,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
251
  requirements: []
251
252
 
252
253
  rubyforge_project:
253
- rubygems_version: 1.5.3
254
+ rubygems_version: 1.4.2
254
255
  signing_key:
255
256
  specification_version: 3
256
257
  summary: Calculation and form building tool hiding details of AMEEconnect