amee-data-abstraction 2.2.0 → 2.2.1

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/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.2.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.2.0"
8
+ s.version = "2.2.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-18}
12
+ s.date = %q{2011-10-25}
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 = [
@@ -62,6 +62,7 @@ Gem::Specification.new do |s|
62
62
  "spec/core-extensions/hash_spec.rb",
63
63
  "spec/core-extensions/ordered_hash_spec.rb",
64
64
  "spec/core-extensions/proc_spec.rb",
65
+ "spec/fixtures/config/calculations/autoloaded.rb",
65
66
  "spec/fixtures/config/calculations/electricity.rb",
66
67
  "spec/fixtures/config/calculations/electricity_and_transport.rb",
67
68
  "spec/fixtures/config/calculations/transport.rb",
@@ -72,7 +73,7 @@ Gem::Specification.new do |s|
72
73
  s.homepage = %q{http://github.com/AMEE/amee-data-abstraction}
73
74
  s.licenses = ["BSD 3-Clause"]
74
75
  s.require_paths = ["lib"]
75
- s.rubygems_version = %q{1.5.3}
76
+ s.rubygems_version = %q{1.6.2}
76
77
  s.summary = %q{Calculation and form building tool hiding details of AMEEconnect}
77
78
 
78
79
  if s.respond_to? :specification_version then
@@ -65,10 +65,18 @@ module AMEE
65
65
  set.generate_lock_file(output_path)
66
66
  end
67
67
 
68
+ DEFAULT_RAILS_CONFIG_DIR = "config/calculations"
69
+
68
70
  # Find a specific prototype calculation instance without specifying the set
69
71
  # to which it belongs.
70
72
  #
71
73
  def self.find_prototype_calculation(label)
74
+ # Make sure all sets are loaded first
75
+ default_config_dir = defined?(::Rails) ? "#{::Rails.root}/#{DEFAULT_RAILS_CONFIG_DIR}" : DEFAULT_RAILS_CONFIG_DIR
76
+ Dir.glob(default_config_dir + "/*.rb").each do |name|
77
+ find(name)
78
+ end
79
+ # Then search them
72
80
  @@sets.each_pair do |name,set|
73
81
  set = find(name)
74
82
  return set[label] if set[label]
@@ -85,14 +93,12 @@ module AMEE
85
93
  end
86
94
  end
87
95
 
88
- DEFFAULT_RAILS_CONFIG_DIR = "config/calculations"
89
-
90
96
  # Find the config file assocaited with <tt>name</tt>. The method first checks
91
97
  # the default Rails configuration location (config/calculations) then the
92
98
  # file path described by <tt>name</tt> relative to the Rails root and by
93
99
  # absolute path.
94
100
  def self.find_config_file(name)
95
- default_config_dir = defined?(::Rails) ? "#{::Rails.root}/#{DEFFAULT_RAILS_CONFIG_DIR}" : nil
101
+ default_config_dir = defined?(::Rails) ? "#{::Rails.root}/#{DEFAULT_RAILS_CONFIG_DIR}" : nil
96
102
  if defined?(::Rails) && File.exists?("#{default_config_dir}/#{name.to_s}.rb")
97
103
  "#{default_config_dir}/#{name.to_s}.rb"
98
104
  elsif defined?(::Rails) && File.exists?("#{default_config_dir}/#{name.to_s}")
@@ -201,6 +201,10 @@ module AMEE
201
201
  def dirty?
202
202
  @dirty
203
203
  end
204
+
205
+ def clean!
206
+ @dirty = false
207
+ end
204
208
 
205
209
  protected
206
210
  # Returns <tt>true</tt> if the value set for <tt>self</tt> is either blank
@@ -79,6 +79,7 @@ module AMEE
79
79
  # for results to be valid.
80
80
  #
81
81
  def clean!
82
+ inputs.each{|i| i.clean!}
82
83
  @dirty=false
83
84
  end
84
85
 
@@ -86,6 +86,16 @@ describe CalculationSet do
86
86
  set = CalculationSet.find('transport')
87
87
  end
88
88
 
89
+ it "should only call load_set once for the same set" do
90
+ CalculationSet.sets[:transport].should be_nil
91
+ CalculationSet.sets.count.should == 0
92
+ set_a = CalculationSet.find('transport')
93
+ CalculationSet.sets.count.should == 1
94
+ set_b = CalculationSet.find('transport')
95
+ CalculationSet.sets.count.should == 1
96
+ set_a.should be(set_b)
97
+ end
98
+
89
99
  it "should not call load_set if set exists in class hash" do
90
100
  CalculationSet.sets[:transport].should be_nil
91
101
  set = CalculationSet.find('transport')
@@ -248,6 +258,13 @@ describe CalculationSet do
248
258
  CalculationSet.find_prototype_calculation(:my_other_calc).should be_a PrototypeCalculation
249
259
  end
250
260
 
261
+ it "can find a prototype calc without calc set" do
262
+ # Shouldn't be loaded
263
+ CalculationSet.sets[:autoloaded].should be_nil
264
+ # Should be autoloaded (along with the rest) when find_prototype_calculation is used
265
+ CalculationSet.find_prototype_calculation(:autocalc).should be_a PrototypeCalculation
266
+ end
267
+
251
268
  it "returns nil where no prototype calcualtion is found" do
252
269
  CalculationSet.find_prototype_calculation(:fuel).should be_nil
253
270
  end
@@ -114,4 +114,10 @@ describe Input do
114
114
  i.dirty?.should eql true
115
115
  end
116
116
 
117
+ it "should be clean when the value is changed and then marked as clean" do
118
+ i=Input.new
119
+ i.value 5
120
+ i.clean!
121
+ i.dirty?.should be_false
122
+ end
117
123
  end
@@ -225,7 +225,7 @@ describe OngoingCalculation do
225
225
 
226
226
  mocker.existing={'distance'=>5}
227
227
  mocker.params={'distance'=>9}
228
- mocker.update.get(true)
228
+ mocker.update.get(true, true)
229
229
 
230
230
  mycalc=@transport.begin_calculation
231
231
  mycalc.choose!('fuel'=>'diesel','size'=>'large','distance'=>5)
@@ -0,0 +1,26 @@
1
+ calculation {
2
+ name 'autocalc'
3
+ label :autocalc
4
+ path '/transport/car/generic'
5
+
6
+ drill {
7
+ path 'fuel'
8
+ label :fuel
9
+ name 'Fuel Type'
10
+ }
11
+ drill {
12
+ path 'size'
13
+ label :size
14
+ name 'Vehicle Size'
15
+ }
16
+ profile {
17
+ path 'distance'
18
+ label :distance
19
+ name 'Distance Driven'
20
+ }
21
+ output {
22
+ label :co2
23
+ path 'default'
24
+ name 'Carbon Dioxide'
25
+ }
26
+ }
@@ -261,10 +261,16 @@ class AMEEMocker
261
261
  mock_di.should_receive(:value).with(k).and_return(v).once
262
262
  end
263
263
  end
264
- test.flexmock(AMEE::Data::Item).should_receive(:get).
265
- with(connection,dipath,{}).
266
- at_least.once.
267
- and_return(mock_di)
264
+ if once
265
+ test.flexmock(AMEE::Data::Item).should_receive(:get).
266
+ with(connection,dipath,{}).
267
+ at_least.once.
268
+ and_return(mock_di)
269
+ else
270
+ test.flexmock(AMEE::Data::Item).should_receive(:get).
271
+ with(connection,dipath,{}).
272
+ and_return(mock_di)
273
+ end
268
274
  end
269
275
  if once
270
276
  test.flexmock(AMEE::Profile::Item).should_receive(:get).
@@ -272,10 +278,9 @@ class AMEEMocker
272
278
  at_least.once.
273
279
  and_return(mock_pi)
274
280
  else
275
- test.flexmock(AMEE::Profile::Item).should_receive(:get).
276
- with(connection,pipath,{}).
277
- at_least.once.
278
- and_return(mock_pi)
281
+ test.flexmock(AMEE::Profile::Item).should_receive(:get).
282
+ with(connection,pipath,{}).
283
+ and_return(mock_pi)
279
284
  end
280
285
  return self
281
286
  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: 7
4
+ hash: 5
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 2
9
- - 0
10
- version: 2.2.0
9
+ - 1
10
+ version: 2.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Hetherington
@@ -18,12 +18,13 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2011-10-18 00:00:00 +01:00
21
+ date: 2011-10-25 00:00:00 +01:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
25
- name: amee
26
- version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ prerelease: false
26
+ type: :runtime
27
+ requirement: &id001 !ruby/object:Gem::Requirement
27
28
  none: false
28
29
  requirements:
29
30
  - - ~>
@@ -34,12 +35,12 @@ dependencies:
34
35
  - 1
35
36
  - 5
36
37
  version: 4.1.5
38
+ name: amee
39
+ version_requirements: *id001
40
+ - !ruby/object:Gem::Dependency
37
41
  prerelease: false
38
42
  type: :runtime
39
- requirement: *id001
40
- - !ruby/object:Gem::Dependency
41
- name: uuidtools
42
- version_requirements: &id002 !ruby/object:Gem::Requirement
43
+ requirement: &id002 !ruby/object:Gem::Requirement
43
44
  none: false
44
45
  requirements:
45
46
  - - "="
@@ -50,12 +51,12 @@ dependencies:
50
51
  - 1
51
52
  - 2
52
53
  version: 2.1.2
54
+ name: uuidtools
55
+ version_requirements: *id002
56
+ - !ruby/object:Gem::Dependency
53
57
  prerelease: false
54
58
  type: :runtime
55
- requirement: *id002
56
- - !ruby/object:Gem::Dependency
57
- name: quantify
58
- version_requirements: &id003 !ruby/object:Gem::Requirement
59
+ requirement: &id003 !ruby/object:Gem::Requirement
59
60
  none: false
60
61
  requirements:
61
62
  - - ~>
@@ -66,12 +67,12 @@ dependencies:
66
67
  - 0
67
68
  - 0
68
69
  version: 2.0.0
69
- prerelease: false
70
- type: :runtime
71
- requirement: *id003
70
+ name: quantify
71
+ version_requirements: *id003
72
72
  - !ruby/object:Gem::Dependency
73
- name: bundler
74
- version_requirements: &id004 !ruby/object:Gem::Requirement
73
+ prerelease: false
74
+ type: :development
75
+ requirement: &id004 !ruby/object:Gem::Requirement
75
76
  none: false
76
77
  requirements:
77
78
  - - ~>
@@ -82,12 +83,12 @@ dependencies:
82
83
  - 0
83
84
  - 0
84
85
  version: 1.0.0
86
+ name: bundler
87
+ version_requirements: *id004
88
+ - !ruby/object:Gem::Dependency
85
89
  prerelease: false
86
90
  type: :development
87
- requirement: *id004
88
- - !ruby/object:Gem::Dependency
89
- name: jeweler
90
- version_requirements: &id005 !ruby/object:Gem::Requirement
91
+ requirement: &id005 !ruby/object:Gem::Requirement
91
92
  none: false
92
93
  requirements:
93
94
  - - ~>
@@ -98,12 +99,12 @@ dependencies:
98
99
  - 6
99
100
  - 4
100
101
  version: 1.6.4
102
+ name: jeweler
103
+ version_requirements: *id005
104
+ - !ruby/object:Gem::Dependency
101
105
  prerelease: false
102
106
  type: :development
103
- requirement: *id005
104
- - !ruby/object:Gem::Dependency
105
- name: rspec
106
- version_requirements: &id006 !ruby/object:Gem::Requirement
107
+ requirement: &id006 !ruby/object:Gem::Requirement
107
108
  none: false
108
109
  requirements:
109
110
  - - "="
@@ -114,12 +115,12 @@ dependencies:
114
115
  - 6
115
116
  - 0
116
117
  version: 2.6.0
118
+ name: rspec
119
+ version_requirements: *id006
120
+ - !ruby/object:Gem::Dependency
117
121
  prerelease: false
118
122
  type: :development
119
- requirement: *id006
120
- - !ruby/object:Gem::Dependency
121
- name: flexmock
122
- version_requirements: &id007 !ruby/object:Gem::Requirement
123
+ requirement: &id007 !ruby/object:Gem::Requirement
123
124
  none: false
124
125
  requirements:
125
126
  - - ">"
@@ -130,12 +131,12 @@ dependencies:
130
131
  - 8
131
132
  - 6
132
133
  version: 0.8.6
134
+ name: flexmock
135
+ version_requirements: *id007
136
+ - !ruby/object:Gem::Dependency
133
137
  prerelease: false
134
138
  type: :development
135
- requirement: *id007
136
- - !ruby/object:Gem::Dependency
137
- name: rcov
138
- version_requirements: &id008 !ruby/object:Gem::Requirement
139
+ requirement: &id008 !ruby/object:Gem::Requirement
139
140
  none: false
140
141
  requirements:
141
142
  - - ">="
@@ -144,12 +145,12 @@ dependencies:
144
145
  segments:
145
146
  - 0
146
147
  version: "0"
148
+ name: rcov
149
+ version_requirements: *id008
150
+ - !ruby/object:Gem::Dependency
147
151
  prerelease: false
148
152
  type: :development
149
- requirement: *id008
150
- - !ruby/object:Gem::Dependency
151
- name: rdoc
152
- version_requirements: &id009 !ruby/object:Gem::Requirement
153
+ requirement: &id009 !ruby/object:Gem::Requirement
153
154
  none: false
154
155
  requirements:
155
156
  - - ">="
@@ -158,9 +159,8 @@ dependencies:
158
159
  segments:
159
160
  - 0
160
161
  version: "0"
161
- prerelease: false
162
- type: :development
163
- requirement: *id009
162
+ name: rdoc
163
+ version_requirements: *id009
164
164
  description: Part of the AMEEappkit this gem provides a data abstraction layer, decreasing the amount and detail of development required
165
165
  email: help@amee.com
166
166
  executables: []
@@ -216,6 +216,7 @@ files:
216
216
  - spec/core-extensions/hash_spec.rb
217
217
  - spec/core-extensions/ordered_hash_spec.rb
218
218
  - spec/core-extensions/proc_spec.rb
219
+ - spec/fixtures/config/calculations/autoloaded.rb
219
220
  - spec/fixtures/config/calculations/electricity.rb
220
221
  - spec/fixtures/config/calculations/electricity_and_transport.rb
221
222
  - spec/fixtures/config/calculations/transport.rb
@@ -252,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
252
253
  requirements: []
253
254
 
254
255
  rubyforge_project:
255
- rubygems_version: 1.5.3
256
+ rubygems_version: 1.6.2
256
257
  signing_key:
257
258
  specification_version: 3
258
259
  summary: Calculation and form building tool hiding details of AMEEconnect