amee-data-persistence 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc CHANGED
@@ -1 +1 @@
1
- rvm 1.8.7@amee-data-persistence
1
+ rvm 1.8.7@amee-data-persistence-rails2
data/CHANGELOG.txt CHANGED
@@ -1,4 +1,7 @@
1
1
  = Changelog
2
2
 
3
+ == 1.2.0
4
+ * Update for supporting the new handling of Calculation Sets in amee-data-abstraction
5
+
3
6
  == 1.0.0
4
7
  * Initial public release
data/Gemfile CHANGED
@@ -1,7 +1,7 @@
1
1
  source "http://rubygems.org"
2
2
 
3
3
  # Dependencies
4
- gem "amee-data-abstraction","~> 1.1"
4
+ gem "amee-data-abstraction","~> 1.3"
5
5
 
6
6
  # Add dependencies to develop your gem here.
7
7
  # Include everything needed to run rake, tests, features, etc.
data/Gemfile.lock CHANGED
@@ -4,14 +4,14 @@ GEM
4
4
  activerecord (2.3.12)
5
5
  activesupport (= 2.3.12)
6
6
  activesupport (2.3.12)
7
- amee (3.0.1)
7
+ amee (3.1.2)
8
8
  activesupport (~> 2.3.5)
9
9
  json
10
10
  log4r
11
11
  nokogiri (~> 1.4.3.1)
12
- amee-data-abstraction (1.1.0)
13
- amee (~> 3.0)
14
- quantify (= 1.2.0)
12
+ amee-data-abstraction (1.3.0)
13
+ amee (~> 3.1)
14
+ quantify (= 1.2.2)
15
15
  uuidtools (= 2.1.2)
16
16
  flexmock (0.9.0)
17
17
  git (1.2.5)
@@ -23,7 +23,7 @@ GEM
23
23
  json (1.5.3)
24
24
  log4r (1.1.9)
25
25
  nokogiri (1.4.3.1)
26
- quantify (1.2.0)
26
+ quantify (1.2.2)
27
27
  activesupport
28
28
  i18n
29
29
  rake (0.9.2)
@@ -40,7 +40,7 @@ PLATFORMS
40
40
 
41
41
  DEPENDENCIES
42
42
  activerecord (~> 2.3.5)
43
- amee-data-abstraction (~> 1.1)
43
+ amee-data-abstraction (~> 1.3)
44
44
  bundler (~> 1.0.0)
45
45
  flexmock (> 0.8.6)
46
46
  jeweler (~> 1.6.4)
data/README.txt CHANGED
@@ -86,4 +86,7 @@ where <storage_level> can be either 'everything', 'outputs' or 'metadata', e.g.,
86
86
 
87
87
  my_calculation.save #=> true
88
88
 
89
- my_calculation.delete #=> nil
89
+ my_calculation.delete #=> nil
90
+
91
+ In order to use the persistence library, prototype calculations must be held within
92
+ instances of the AMEE::DataAbstraction::CalculationSet class
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{amee-data-persistence}
8
- s.version = "1.1.0"
8
+ s.version = "1.2.0"
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-08-30}
12
+ s.date = %q{2011-10-18}
13
13
  s.description = %q{Part of the AMEEappkit, this gem provides storage and retrival of data provided by the amee-data-abstraction gem}
14
14
  s.email = %q{help@amee.com}
15
15
  s.extra_rdoc_files = [
@@ -35,15 +35,17 @@ Gem::Specification.new do |s|
35
35
  "init.rb",
36
36
  "lib/amee-data-persistence.rb",
37
37
  "lib/amee/data_abstraction/calculation_collection.rb",
38
- "lib/amee/data_abstraction/persistence_support.rb",
38
+ "lib/amee/data_abstraction/ongoing_calculation_persistence_support.rb",
39
39
  "lib/amee/db/calculation.rb",
40
40
  "lib/amee/db/config.rb",
41
41
  "lib/amee/db/term.rb",
42
42
  "rails/init.rb",
43
43
  "spec/amee/db/calculation_spec.rb",
44
44
  "spec/amee/db/config_spec.rb",
45
- "spec/amee/db/persistence_support_spec.rb",
45
+ "spec/amee/db/ongoing_calculation_persistence_support_spec.rb",
46
46
  "spec/amee/db/term_spec.rb",
47
+ "spec/amee/fixtures/config/calculations/electricity.lock.rb",
48
+ "spec/amee/fixtures/config/calculations/electricity.rb",
47
49
  "spec/database.yml",
48
50
  "spec/spec.opts",
49
51
  "spec/spec_helper.rb"
@@ -51,14 +53,14 @@ Gem::Specification.new do |s|
51
53
  s.homepage = %q{http://github.com/AMEE/amee-data-persistence}
52
54
  s.licenses = ["BSD 3-Clause"]
53
55
  s.require_paths = ["lib"]
54
- s.rubygems_version = %q{1.6.2}
56
+ s.rubygems_version = %q{1.5.3}
55
57
  s.summary = %q{Persistent storage of calculations performed against the AMEE API}
56
58
 
57
59
  if s.respond_to? :specification_version then
58
60
  s.specification_version = 3
59
61
 
60
62
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
- s.add_runtime_dependency(%q<amee-data-abstraction>, ["~> 1.1"])
63
+ s.add_runtime_dependency(%q<amee-data-abstraction>, ["~> 1.3"])
62
64
  s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
63
65
  s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
64
66
  s.add_development_dependency(%q<rspec>, ["= 1.3.0"])
@@ -68,7 +70,7 @@ Gem::Specification.new do |s|
68
70
  s.add_development_dependency(%q<activerecord>, ["~> 2.3.5"])
69
71
  s.add_development_dependency(%q<sqlite3>, [">= 0"])
70
72
  else
71
- s.add_dependency(%q<amee-data-abstraction>, ["~> 1.1"])
73
+ s.add_dependency(%q<amee-data-abstraction>, ["~> 1.3"])
72
74
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
73
75
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
74
76
  s.add_dependency(%q<rspec>, ["= 1.3.0"])
@@ -79,7 +81,7 @@ Gem::Specification.new do |s|
79
81
  s.add_dependency(%q<sqlite3>, [">= 0"])
80
82
  end
81
83
  else
82
- s.add_dependency(%q<amee-data-abstraction>, ["~> 1.1"])
84
+ s.add_dependency(%q<amee-data-abstraction>, ["~> 1.3"])
83
85
  s.add_dependency(%q<bundler>, ["~> 1.0.0"])
84
86
  s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
85
87
  s.add_dependency(%q<rspec>, ["= 1.3.0"])
@@ -7,6 +7,7 @@ require 'active_record'
7
7
  require 'quantify'
8
8
 
9
9
  require 'amee/data_abstraction/calculation_collection'
10
+ require 'amee/data_abstraction/ongoing_calculation_persistence_support'
10
11
  require 'amee/db/calculation'
11
12
  require 'amee/db/term'
12
13
  require 'amee/db/config'
@@ -223,7 +223,7 @@ module AMEE
223
223
  unless record.is_a? AMEE::Db::Calculation
224
224
  raise ArgumentError.new("Argument is not of class AMEE::Db::Calculation")
225
225
  end
226
- calc = Calculations.calculations[record.type].begin_calculation
226
+ calc = AMEE::DataAbstraction::CalculationSet.find_prototype_calculation(record.type).begin_calculation
227
227
  calc.db_calculation = record
228
228
  # Means that validation needs to occur before calcs are saved
229
229
  calc.choose_without_validation!(record.to_hash)
@@ -39,7 +39,7 @@ module AMEE
39
39
  private
40
40
 
41
41
  def load_storage_method
42
- m = YAML.load_file("#{RAILS_ROOT}/config/persistence.yml")['method'].to_sym rescue nil
42
+ m = YAML.load_file("#{::Rails.root}/config/persistence.yml")['method'].to_sym rescue nil
43
43
  raise "amee-data-persistence: Invalid storage method" unless [:metadata, :outputs, :everything].include? m
44
44
  m
45
45
  end
@@ -4,7 +4,7 @@ describe AMEE::DataAbstraction::OngoingCalculation do
4
4
 
5
5
  before(:all) do
6
6
  populate_db
7
- initialize_calculation_set
7
+ AMEE::DataAbstraction::CalculationSet.find("electricity")
8
8
  end
9
9
 
10
10
  after(:all) do
@@ -133,8 +133,8 @@ describe AMEE::DataAbstraction::OngoingCalculation do
133
133
 
134
134
 
135
135
  it "should give nil id, if not saved" do
136
- Calculations[:electricity].begin_calculation.db_calculation.should be_nil
137
- Calculations[:electricity].begin_calculation.id.should be_nil
136
+ AMEE::DataAbstraction::CalculationSet.find("electricity")[:electricity].begin_calculation.db_calculation.should be_nil
137
+ AMEE::DataAbstraction::CalculationSet.find("electricity")[:electricity].begin_calculation.id.should be_nil
138
138
  end
139
139
  end
140
140
 
@@ -0,0 +1,30 @@
1
+ calculation {
2
+
3
+ name "Electricity"
4
+ label :electricity
5
+ path "/business/energy/electricity/grid"
6
+
7
+ drill {
8
+ name "Country"
9
+ label :country
10
+ path "country"
11
+ value "Argentina"
12
+ fixed "Argentina"
13
+ interface :drop_down
14
+ }
15
+
16
+ profile {
17
+ name "Electricity Used"
18
+ label :usage
19
+ path "energyPerTime"
20
+ interface :text_box
21
+ }
22
+
23
+ output {
24
+ name "Carbon Dioxide"
25
+ label :co2
26
+ path "default"
27
+ }
28
+
29
+ }
30
+
@@ -0,0 +1,20 @@
1
+ calculation {
2
+ name 'Electricity'
3
+ label :electricity
4
+ path '/business/energy/electricity/grid'
5
+ drill {
6
+ label :country
7
+ path 'country'
8
+ fixed 'Argentina'
9
+ }
10
+ profile {
11
+ label :usage
12
+ name 'Electricity Used'
13
+ path 'energyPerTime'
14
+ }
15
+ output {
16
+ label :co2
17
+ name 'Carbon Dioxide'
18
+ path 'default'
19
+ }
20
+ }
data/spec/spec_helper.rb CHANGED
@@ -6,14 +6,18 @@ require 'logger'
6
6
  gem 'amee-data-abstraction'
7
7
  require 'amee-data-abstraction'
8
8
 
9
- RAILS_ROOT = '.'
10
-
11
9
  DB_CONFIG = YAML.load_file(File.dirname(__FILE__) + '/database.yml')
12
10
  DB_MIGRATION = File.join(File.dirname(__FILE__), '..','generators','persistence','templates','db','migrate')
13
11
 
12
+ class Rails
13
+ def self.root
14
+ File.dirname(__FILE__) + '/amee/fixtures'
15
+ end
16
+ end
17
+
14
18
  $:.unshift(File.dirname(__FILE__) + '/../lib')
15
19
  require 'amee-data-persistence'
16
- require 'amee/data_abstraction/persistence_support'
20
+ require 'amee/data_abstraction/ongoing_calculation_persistence_support'
17
21
 
18
22
  ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a'))
19
23
  AMEE::DataAbstraction::OngoingCalculation.class_eval { include AMEE::DataAbstraction::PersistenceSupport }
@@ -66,71 +70,3 @@ def populate_db
66
70
  AMEE::Db::Calculation.new { |calc| calc.update_calculation! attr }
67
71
  end
68
72
  end
69
-
70
- def initialize_calculation_set
71
- eval "Calculations = AMEE::DataAbstraction::CalculationSet.new {
72
- calculation{
73
- name 'Electricity'
74
- label :electricity
75
- path '/business/energy/electricity/grid'
76
- drill {
77
- label :country
78
- path 'country'
79
- fixed 'Argentina'
80
- }
81
- profile {
82
- label :usage
83
- name 'Electricity Used'
84
- path 'energyPerTime'
85
- }
86
- output {
87
- label :co2
88
- name 'Carbon Dioxide'
89
- path :default
90
- }
91
- }
92
- }"
93
- end
94
-
95
-
96
- # Stub activerecord for rails tests
97
- # Taken from http://muness.blogspot.com/2006/12/unit-testing-rails-activerecord-classes.html
98
- #class ActiveRecordUnitTestHelper
99
- # attr_accessor :klass
100
- #
101
- # def initialize klass
102
- # self.klass = klass
103
- # self
104
- # end
105
- #
106
- # def where attributes
107
- # klass.stubs(:columns).returns(columns(attributes))
108
- # instance = klass.new(attributes)
109
- # instance.id = attributes[:id] if attributes[:id] #the id attributes works differently on active record classes
110
- # instance
111
- # end
112
- #
113
- #protected
114
- # def columns attributes
115
- # attributes.keys.collect{|attribute| column attribute.to_s, attributes[attribute]}
116
- # end
117
- #
118
- # def column column_name, value
119
- # ActiveRecord::ConnectionAdapters::Column.new(column_name, nil, ActiveRecordUnitTestHelper.active_record_type(value.class), false)
120
- # end
121
- #
122
- # def self.active_record_type klass
123
- # return case klass.name
124
- # when "Fixnum" then "integer"
125
- # when "Float" then "float"
126
- # when "Time" then "time"
127
- # when "Date" then "date"
128
- # when "String" then "string"
129
- # when "Object" then "boolean"
130
- # end
131
- # end
132
- #end
133
- #
134
- #def disconnected klass
135
- # ActiveRecordUnitTestHelper.new(klass)
136
- #ßend
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amee-data-persistence
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 31
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 1.1.0
10
+ version: 1.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - James Hetherington
@@ -18,28 +18,27 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2011-08-30 00:00:00 +01:00
21
+ date: 2011-10-18 00:00:00 +01:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
25
- prerelease: false
26
- type: :runtime
27
- requirement: &id001 !ruby/object:Gem::Requirement
25
+ name: amee-data-abstraction
26
+ version_requirements: &id001 !ruby/object:Gem::Requirement
28
27
  none: false
29
28
  requirements:
30
29
  - - ~>
31
30
  - !ruby/object:Gem::Version
32
- hash: 13
31
+ hash: 9
33
32
  segments:
34
33
  - 1
35
- - 1
36
- version: "1.1"
37
- name: amee-data-abstraction
38
- version_requirements: *id001
39
- - !ruby/object:Gem::Dependency
34
+ - 3
35
+ version: "1.3"
40
36
  prerelease: false
41
- type: :development
42
- requirement: &id002 !ruby/object:Gem::Requirement
37
+ type: :runtime
38
+ requirement: *id001
39
+ - !ruby/object:Gem::Dependency
40
+ name: bundler
41
+ version_requirements: &id002 !ruby/object:Gem::Requirement
43
42
  none: false
44
43
  requirements:
45
44
  - - ~>
@@ -50,12 +49,12 @@ dependencies:
50
49
  - 0
51
50
  - 0
52
51
  version: 1.0.0
53
- name: bundler
54
- version_requirements: *id002
55
- - !ruby/object:Gem::Dependency
56
52
  prerelease: false
57
53
  type: :development
58
- requirement: &id003 !ruby/object:Gem::Requirement
54
+ requirement: *id002
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
57
+ version_requirements: &id003 !ruby/object:Gem::Requirement
59
58
  none: false
60
59
  requirements:
61
60
  - - ~>
@@ -66,12 +65,12 @@ dependencies:
66
65
  - 6
67
66
  - 4
68
67
  version: 1.6.4
69
- name: jeweler
70
- version_requirements: *id003
71
- - !ruby/object:Gem::Dependency
72
68
  prerelease: false
73
69
  type: :development
74
- requirement: &id004 !ruby/object:Gem::Requirement
70
+ requirement: *id003
71
+ - !ruby/object:Gem::Dependency
72
+ name: rspec
73
+ version_requirements: &id004 !ruby/object:Gem::Requirement
75
74
  none: false
76
75
  requirements:
77
76
  - - "="
@@ -82,12 +81,12 @@ dependencies:
82
81
  - 3
83
82
  - 0
84
83
  version: 1.3.0
85
- name: rspec
86
- version_requirements: *id004
87
- - !ruby/object:Gem::Dependency
88
84
  prerelease: false
89
85
  type: :development
90
- requirement: &id005 !ruby/object:Gem::Requirement
86
+ requirement: *id004
87
+ - !ruby/object:Gem::Dependency
88
+ name: rcov
89
+ version_requirements: &id005 !ruby/object:Gem::Requirement
91
90
  none: false
92
91
  requirements:
93
92
  - - ">="
@@ -96,12 +95,12 @@ dependencies:
96
95
  segments:
97
96
  - 0
98
97
  version: "0"
99
- name: rcov
100
- version_requirements: *id005
101
- - !ruby/object:Gem::Dependency
102
98
  prerelease: false
103
99
  type: :development
104
- requirement: &id006 !ruby/object:Gem::Requirement
100
+ requirement: *id005
101
+ - !ruby/object:Gem::Dependency
102
+ name: rspec_spinner
103
+ version_requirements: &id006 !ruby/object:Gem::Requirement
105
104
  none: false
106
105
  requirements:
107
106
  - - "="
@@ -112,12 +111,12 @@ dependencies:
112
111
  - 1
113
112
  - 3
114
113
  version: 1.1.3
115
- name: rspec_spinner
116
- version_requirements: *id006
117
- - !ruby/object:Gem::Dependency
118
114
  prerelease: false
119
115
  type: :development
120
- requirement: &id007 !ruby/object:Gem::Requirement
116
+ requirement: *id006
117
+ - !ruby/object:Gem::Dependency
118
+ name: flexmock
119
+ version_requirements: &id007 !ruby/object:Gem::Requirement
121
120
  none: false
122
121
  requirements:
123
122
  - - ">"
@@ -128,12 +127,12 @@ dependencies:
128
127
  - 8
129
128
  - 6
130
129
  version: 0.8.6
131
- name: flexmock
132
- version_requirements: *id007
133
- - !ruby/object:Gem::Dependency
134
130
  prerelease: false
135
131
  type: :development
136
- requirement: &id008 !ruby/object:Gem::Requirement
132
+ requirement: *id007
133
+ - !ruby/object:Gem::Dependency
134
+ name: activerecord
135
+ version_requirements: &id008 !ruby/object:Gem::Requirement
137
136
  none: false
138
137
  requirements:
139
138
  - - ~>
@@ -144,12 +143,12 @@ dependencies:
144
143
  - 3
145
144
  - 5
146
145
  version: 2.3.5
147
- name: activerecord
148
- version_requirements: *id008
149
- - !ruby/object:Gem::Dependency
150
146
  prerelease: false
151
147
  type: :development
152
- requirement: &id009 !ruby/object:Gem::Requirement
148
+ requirement: *id008
149
+ - !ruby/object:Gem::Dependency
150
+ name: sqlite3
151
+ version_requirements: &id009 !ruby/object:Gem::Requirement
153
152
  none: false
154
153
  requirements:
155
154
  - - ">="
@@ -158,8 +157,9 @@ dependencies:
158
157
  segments:
159
158
  - 0
160
159
  version: "0"
161
- name: sqlite3
162
- version_requirements: *id009
160
+ prerelease: false
161
+ type: :development
162
+ requirement: *id009
163
163
  description: Part of the AMEEappkit, this gem provides storage and retrival of data provided by the amee-data-abstraction gem
164
164
  email: help@amee.com
165
165
  executables: []
@@ -188,15 +188,17 @@ files:
188
188
  - init.rb
189
189
  - lib/amee-data-persistence.rb
190
190
  - lib/amee/data_abstraction/calculation_collection.rb
191
- - lib/amee/data_abstraction/persistence_support.rb
191
+ - lib/amee/data_abstraction/ongoing_calculation_persistence_support.rb
192
192
  - lib/amee/db/calculation.rb
193
193
  - lib/amee/db/config.rb
194
194
  - lib/amee/db/term.rb
195
195
  - rails/init.rb
196
196
  - spec/amee/db/calculation_spec.rb
197
197
  - spec/amee/db/config_spec.rb
198
- - spec/amee/db/persistence_support_spec.rb
198
+ - spec/amee/db/ongoing_calculation_persistence_support_spec.rb
199
199
  - spec/amee/db/term_spec.rb
200
+ - spec/amee/fixtures/config/calculations/electricity.lock.rb
201
+ - spec/amee/fixtures/config/calculations/electricity.rb
200
202
  - spec/database.yml
201
203
  - spec/spec.opts
202
204
  - spec/spec_helper.rb
@@ -230,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
230
232
  requirements: []
231
233
 
232
234
  rubyforge_project:
233
- rubygems_version: 1.6.2
235
+ rubygems_version: 1.5.3
234
236
  signing_key:
235
237
  specification_version: 3
236
238
  summary: Persistent storage of calculations performed against the AMEE API