amee-data-persistence 1.2.0 → 2.0.0
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/.rvmrc +1 -1
- data/CHANGELOG.txt +0 -3
- data/Gemfile +6 -9
- data/Gemfile.lock +36 -20
- data/README.txt +3 -6
- data/Rakefile +15 -29
- data/VERSION +1 -1
- data/amee-data-persistence.gemspec +25 -29
- data/lib/amee-data-persistence.rb +4 -2
- data/lib/amee/data_abstraction/{ongoing_calculation_persistence_support.rb → persistence_support.rb} +1 -1
- data/lib/amee/db/calculation.rb +3 -3
- data/lib/amee/db/config.rb +1 -1
- data/lib/amee/db/term.rb +2 -1
- data/lib/generators/persistence/persistence_generator.rb +41 -0
- data/{generators → lib/generators}/persistence/templates/config/persistence.yml.erb +0 -0
- data/{generators → lib/generators}/persistence/templates/db/migrate/001_create_persistence_tables.rb +0 -0
- data/{generators → lib/generators}/persistence/templates/db/migrate/002_add_unit_columns.rb +0 -0
- data/{generators → lib/generators}/persistence/templates/db/migrate/003_add_value_types.rb +0 -0
- data/spec/amee/db/calculation_spec.rb +1 -1
- data/spec/amee/db/config_spec.rb +1 -1
- data/spec/amee/db/{ongoing_calculation_persistence_support_spec.rb → persistence_support_spec.rb} +39 -41
- data/spec/amee/db/term_spec.rb +1 -1
- data/spec/spec_helper.rb +33 -20
- metadata +70 -76
- data/generators/persistence/persistence_generator.rb +0 -97
- data/init.rb +0 -1
- data/rails/init.rb +0 -31
- data/spec/amee/fixtures/config/calculations/electricity.lock.rb +0 -30
- data/spec/amee/fixtures/config/calculations/electricity.rb +0 -20
data/.rvmrc
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rvm 1.8.7@amee-data-persistence
|
1
|
+
rvm 1.8.7@amee-data-persistence
|
data/CHANGELOG.txt
CHANGED
data/Gemfile
CHANGED
@@ -1,17 +1,14 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
|
-
|
4
|
-
gem
|
3
|
+
gem "amee-data-abstraction", "~> 2.0"
|
4
|
+
gem 'activerecord', '~> 3.0.10'
|
5
5
|
|
6
|
-
# Add dependencies to develop your gem here.
|
7
|
-
# Include everything needed to run rake, tests, features, etc.
|
8
6
|
group :development do
|
9
7
|
gem "bundler", "~> 1.0.0"
|
10
8
|
gem "jeweler", "~> 1.6.4"
|
11
|
-
gem 'rspec', '
|
12
|
-
gem 'rcov'
|
13
|
-
gem 'rspec_spinner', '1.1.3'
|
9
|
+
gem 'rspec', '2.6.0'
|
14
10
|
gem 'flexmock', '> 0.8.6'
|
15
|
-
gem '
|
11
|
+
gem 'rcov'
|
12
|
+
gem 'rdoc'
|
16
13
|
gem 'sqlite3'
|
17
|
-
end
|
14
|
+
end
|
data/Gemfile.lock
CHANGED
@@ -1,50 +1,66 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
-
|
5
|
-
activesupport (=
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
activemodel (3.0.10)
|
5
|
+
activesupport (= 3.0.10)
|
6
|
+
builder (~> 2.1.2)
|
7
|
+
i18n (~> 0.5.0)
|
8
|
+
activerecord (3.0.10)
|
9
|
+
activemodel (= 3.0.10)
|
10
|
+
activesupport (= 3.0.10)
|
11
|
+
arel (~> 2.0.10)
|
12
|
+
tzinfo (~> 0.3.23)
|
13
|
+
activesupport (3.0.10)
|
14
|
+
amee (3.0.1)
|
15
|
+
activesupport (~> 3.0.10)
|
9
16
|
json
|
10
17
|
log4r
|
11
18
|
nokogiri (~> 1.4.3.1)
|
12
|
-
amee-data-abstraction (
|
13
|
-
amee (~> 3.
|
14
|
-
quantify (
|
19
|
+
amee-data-abstraction (2.0.0)
|
20
|
+
amee (~> 3.0)
|
21
|
+
quantify (~> 2.0.0)
|
15
22
|
uuidtools (= 2.1.2)
|
23
|
+
arel (2.0.10)
|
24
|
+
builder (2.1.2)
|
25
|
+
diff-lcs (1.1.3)
|
16
26
|
flexmock (0.9.0)
|
17
27
|
git (1.2.5)
|
18
|
-
i18n (0.
|
28
|
+
i18n (0.5.0)
|
19
29
|
jeweler (1.6.4)
|
20
30
|
bundler (~> 1.0)
|
21
31
|
git (>= 1.2.5)
|
22
32
|
rake
|
23
|
-
json (1.5.
|
33
|
+
json (1.5.4)
|
24
34
|
log4r (1.1.9)
|
25
35
|
nokogiri (1.4.3.1)
|
26
|
-
quantify (
|
27
|
-
activesupport
|
36
|
+
quantify (2.0.0)
|
37
|
+
activesupport (~> 3.0.10)
|
28
38
|
i18n
|
29
39
|
rake (0.9.2)
|
30
40
|
rcov (0.9.10)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
41
|
+
rdoc (3.9.4)
|
42
|
+
rspec (2.6.0)
|
43
|
+
rspec-core (~> 2.6.0)
|
44
|
+
rspec-expectations (~> 2.6.0)
|
45
|
+
rspec-mocks (~> 2.6.0)
|
46
|
+
rspec-core (2.6.4)
|
47
|
+
rspec-expectations (2.6.0)
|
48
|
+
diff-lcs (~> 1.1.2)
|
49
|
+
rspec-mocks (2.6.0)
|
35
50
|
sqlite3 (1.3.4)
|
51
|
+
tzinfo (0.3.29)
|
36
52
|
uuidtools (2.1.2)
|
37
53
|
|
38
54
|
PLATFORMS
|
39
55
|
ruby
|
40
56
|
|
41
57
|
DEPENDENCIES
|
42
|
-
activerecord (~>
|
43
|
-
amee-data-abstraction (~>
|
58
|
+
activerecord (~> 3.0.10)
|
59
|
+
amee-data-abstraction (~> 2.0)
|
44
60
|
bundler (~> 1.0.0)
|
45
61
|
flexmock (> 0.8.6)
|
46
62
|
jeweler (~> 1.6.4)
|
47
63
|
rcov
|
48
|
-
|
49
|
-
|
64
|
+
rdoc
|
65
|
+
rspec (= 2.6.0)
|
50
66
|
sqlite3
|
data/README.txt
CHANGED
@@ -47,11 +47,11 @@ and metadata only.
|
|
47
47
|
The global persistence storage level and migrations for the database tables
|
48
48
|
(under /db/migrate) can be generated using the command line generator command:
|
49
49
|
|
50
|
-
$
|
50
|
+
$ rails generate persistence <storage_level>
|
51
51
|
|
52
52
|
where <storage_level> can be either 'everything', 'outputs' or 'metadata', e.g.,
|
53
53
|
|
54
|
-
$
|
54
|
+
$ rails generate persistence everything
|
55
55
|
|
56
56
|
|
57
57
|
=== Example usage
|
@@ -86,7 +86,4 @@ 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
|
90
|
-
|
91
|
-
In order to use the persistence library, prototype calculations must be held within
|
92
|
-
instances of the AMEE::DataAbstraction::CalculationSet class
|
89
|
+
my_calculation.delete #=> nil
|
data/Rakefile
CHANGED
@@ -13,16 +13,14 @@ rescue Bundler::BundlerError => e
|
|
13
13
|
exit e.status_code
|
14
14
|
end
|
15
15
|
require 'rake'
|
16
|
-
require '
|
17
|
-
require '
|
16
|
+
require 'rspec'
|
17
|
+
require 'rspec/core/rake_task'
|
18
18
|
|
19
19
|
task :default => [:spec]
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
t.rcov = true
|
25
|
-
t.rcov_opts = ['--exclude', 'spec,/*ruby*,/*gems*']
|
21
|
+
desc "Run specs"
|
22
|
+
RSpec::Core::RakeTask.new do |t|
|
23
|
+
# Put spec opts in a file named .rspec in root
|
26
24
|
end
|
27
25
|
|
28
26
|
require 'jeweler'
|
@@ -74,29 +72,17 @@ Jeweler::Tasks.new do |gem|
|
|
74
72
|
end
|
75
73
|
Jeweler::RubygemsDotOrgTasks.new
|
76
74
|
|
77
|
-
require 'rake/testtask'
|
78
|
-
Rake::TestTask.new(:test) do |test|
|
79
|
-
test.libs << 'lib' << 'test'
|
80
|
-
test.pattern = 'test/**/test_*.rb'
|
81
|
-
test.verbose = true
|
82
|
-
end
|
83
|
-
|
84
75
|
require 'rcov/rcovtask'
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
test.rcov_opts << '--exclude "gems/*"'
|
76
|
+
desc "Generate code coverage"
|
77
|
+
RSpec::Core::RakeTask.new(:coverage) do |t|
|
78
|
+
t.rcov = true
|
79
|
+
t.rcov_opts = ['--exclude', 'spec']
|
90
80
|
end
|
91
81
|
|
92
|
-
task
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
rdoc.rdoc_dir = 'rdoc'
|
99
|
-
rdoc.title = "amee-data-persistence #{version}"
|
100
|
-
rdoc.rdoc_files.include('README*')
|
101
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
82
|
+
require 'rdoc/task'
|
83
|
+
RDoc::Task.new do |rd|
|
84
|
+
rd.title = "AMEE Data Persistence"
|
85
|
+
rd.rdoc_dir = 'doc'
|
86
|
+
rd.main = "README"
|
87
|
+
rd.rdoc_files.include("README", "lib/**/*.rb")
|
102
88
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.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 = "
|
8
|
+
s.version = "2.0.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-
|
12
|
+
s.date = %q{2011-09-28}
|
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 = [
|
@@ -27,25 +27,21 @@ Gem::Specification.new do |s|
|
|
27
27
|
"VERSION",
|
28
28
|
"amee-data-persistence.gemspec",
|
29
29
|
"amee-data-persistence.tmproj",
|
30
|
-
"generators/persistence/persistence_generator.rb",
|
31
|
-
"generators/persistence/templates/config/persistence.yml.erb",
|
32
|
-
"generators/persistence/templates/db/migrate/001_create_persistence_tables.rb",
|
33
|
-
"generators/persistence/templates/db/migrate/002_add_unit_columns.rb",
|
34
|
-
"generators/persistence/templates/db/migrate/003_add_value_types.rb",
|
35
|
-
"init.rb",
|
36
30
|
"lib/amee-data-persistence.rb",
|
37
31
|
"lib/amee/data_abstraction/calculation_collection.rb",
|
38
|
-
"lib/amee/data_abstraction/
|
32
|
+
"lib/amee/data_abstraction/persistence_support.rb",
|
39
33
|
"lib/amee/db/calculation.rb",
|
40
34
|
"lib/amee/db/config.rb",
|
41
35
|
"lib/amee/db/term.rb",
|
42
|
-
"
|
36
|
+
"lib/generators/persistence/persistence_generator.rb",
|
37
|
+
"lib/generators/persistence/templates/config/persistence.yml.erb",
|
38
|
+
"lib/generators/persistence/templates/db/migrate/001_create_persistence_tables.rb",
|
39
|
+
"lib/generators/persistence/templates/db/migrate/002_add_unit_columns.rb",
|
40
|
+
"lib/generators/persistence/templates/db/migrate/003_add_value_types.rb",
|
43
41
|
"spec/amee/db/calculation_spec.rb",
|
44
42
|
"spec/amee/db/config_spec.rb",
|
45
|
-
"spec/amee/db/
|
43
|
+
"spec/amee/db/persistence_support_spec.rb",
|
46
44
|
"spec/amee/db/term_spec.rb",
|
47
|
-
"spec/amee/fixtures/config/calculations/electricity.lock.rb",
|
48
|
-
"spec/amee/fixtures/config/calculations/electricity.rb",
|
49
45
|
"spec/database.yml",
|
50
46
|
"spec/spec.opts",
|
51
47
|
"spec/spec_helper.rb"
|
@@ -53,42 +49,42 @@ Gem::Specification.new do |s|
|
|
53
49
|
s.homepage = %q{http://github.com/AMEE/amee-data-persistence}
|
54
50
|
s.licenses = ["BSD 3-Clause"]
|
55
51
|
s.require_paths = ["lib"]
|
56
|
-
s.rubygems_version = %q{1.
|
52
|
+
s.rubygems_version = %q{1.4.2}
|
57
53
|
s.summary = %q{Persistent storage of calculations performed against the AMEE API}
|
58
54
|
|
59
55
|
if s.respond_to? :specification_version then
|
60
56
|
s.specification_version = 3
|
61
57
|
|
62
58
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
63
|
-
s.add_runtime_dependency(%q<amee-data-abstraction>, ["~>
|
59
|
+
s.add_runtime_dependency(%q<amee-data-abstraction>, ["~> 2.0"])
|
60
|
+
s.add_runtime_dependency(%q<activerecord>, ["~> 3.0.10"])
|
64
61
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
62
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.4"])
|
66
|
-
s.add_development_dependency(%q<rspec>, ["=
|
67
|
-
s.add_development_dependency(%q<rcov>, [">= 0"])
|
68
|
-
s.add_development_dependency(%q<rspec_spinner>, ["= 1.1.3"])
|
63
|
+
s.add_development_dependency(%q<rspec>, ["= 2.6.0"])
|
69
64
|
s.add_development_dependency(%q<flexmock>, ["> 0.8.6"])
|
70
|
-
s.add_development_dependency(%q<
|
65
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
66
|
+
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
71
67
|
s.add_development_dependency(%q<sqlite3>, [">= 0"])
|
72
68
|
else
|
73
|
-
s.add_dependency(%q<amee-data-abstraction>, ["~>
|
69
|
+
s.add_dependency(%q<amee-data-abstraction>, ["~> 2.0"])
|
70
|
+
s.add_dependency(%q<activerecord>, ["~> 3.0.10"])
|
74
71
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
75
72
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
76
|
-
s.add_dependency(%q<rspec>, ["=
|
77
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
78
|
-
s.add_dependency(%q<rspec_spinner>, ["= 1.1.3"])
|
73
|
+
s.add_dependency(%q<rspec>, ["= 2.6.0"])
|
79
74
|
s.add_dependency(%q<flexmock>, ["> 0.8.6"])
|
80
|
-
s.add_dependency(%q<
|
75
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
76
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
81
77
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
82
78
|
end
|
83
79
|
else
|
84
|
-
s.add_dependency(%q<amee-data-abstraction>, ["~>
|
80
|
+
s.add_dependency(%q<amee-data-abstraction>, ["~> 2.0"])
|
81
|
+
s.add_dependency(%q<activerecord>, ["~> 3.0.10"])
|
85
82
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
86
83
|
s.add_dependency(%q<jeweler>, ["~> 1.6.4"])
|
87
|
-
s.add_dependency(%q<rspec>, ["=
|
88
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
89
|
-
s.add_dependency(%q<rspec_spinner>, ["= 1.1.3"])
|
84
|
+
s.add_dependency(%q<rspec>, ["= 2.6.0"])
|
90
85
|
s.add_dependency(%q<flexmock>, ["> 0.8.6"])
|
91
|
-
s.add_dependency(%q<
|
86
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
87
|
+
s.add_dependency(%q<rdoc>, [">= 0"])
|
92
88
|
s.add_dependency(%q<sqlite3>, [">= 0"])
|
93
89
|
end
|
94
90
|
end
|
@@ -2,12 +2,14 @@
|
|
2
2
|
# Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.
|
3
3
|
|
4
4
|
require 'rubygems'
|
5
|
-
gem 'activerecord', "~> 2.3.9"
|
6
5
|
require 'active_record'
|
7
6
|
require 'quantify'
|
7
|
+
require 'amee-data-abstraction'
|
8
8
|
|
9
9
|
require 'amee/data_abstraction/calculation_collection'
|
10
|
-
require 'amee/data_abstraction/
|
10
|
+
require 'amee/data_abstraction/persistence_support'
|
11
11
|
require 'amee/db/calculation'
|
12
12
|
require 'amee/db/term'
|
13
13
|
require 'amee/db/config'
|
14
|
+
|
15
|
+
::AMEE::DataAbstraction::OngoingCalculation.send :include, ::AMEE::DataAbstraction::PersistenceSupport
|
data/lib/amee/data_abstraction/{ongoing_calculation_persistence_support.rb → persistence_support.rb}
RENAMED
@@ -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 =
|
226
|
+
calc = Calculations.calculations[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)
|
data/lib/amee/db/calculation.rb
CHANGED
@@ -22,9 +22,9 @@ module AMEE
|
|
22
22
|
class Calculation < ActiveRecord::Base
|
23
23
|
|
24
24
|
has_many :terms, :class_name => "AMEE::Db::Term", :dependent => :destroy
|
25
|
-
|
26
|
-
|
27
|
-
|
25
|
+
validates :calculation_type, :presence => true
|
26
|
+
validates :profile_item_uid, :format => {:with => /\A([A-Z0-9]{12})\z/, :allow_nil => true, :allow_blank => true}
|
27
|
+
validates :profile_uid, :format => {:with => /\A([A-Z0-9]{12})\z/, :allow_nil => true, :allow_blank => true}
|
28
28
|
before_save :validate_calculation_type
|
29
29
|
|
30
30
|
# Standardize the <tt>calculation_type</tt> attribute to <i>String</i>
|
data/lib/amee/db/config.rb
CHANGED
@@ -39,7 +39,7 @@ module AMEE
|
|
39
39
|
private
|
40
40
|
|
41
41
|
def load_storage_method
|
42
|
-
m = YAML.load_file("#{
|
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
|
data/lib/amee/db/term.rb
CHANGED
@@ -20,7 +20,8 @@ module AMEE
|
|
20
20
|
class Term < ActiveRecord::Base
|
21
21
|
|
22
22
|
belongs_to :calculation, :class_name => "AMEE::Db::Calculation"
|
23
|
-
|
23
|
+
validates :calculation_id, :presence => true
|
24
|
+
validates :label, :presence => true
|
24
25
|
before_save :initialize_units
|
25
26
|
before_save :initialize_value
|
26
27
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
|
4
|
+
class PersistenceGenerator < Rails::Generators::Base
|
5
|
+
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
|
8
|
+
desc "Generates a migration for the AMEE Organisation models"
|
9
|
+
def self.source_root
|
10
|
+
@source_root ||= File.dirname(__FILE__) + '/templates'
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.next_migration_number(path)
|
14
|
+
ActiveRecord::Generators::Base.next_migration_number(path)
|
15
|
+
end
|
16
|
+
|
17
|
+
def generate_migration
|
18
|
+
migration_template 'db/migrate/001_create_persistence_tables.rb', 'db/migrate/create_persistence_tables'
|
19
|
+
migration_template 'db/migrate/002_add_unit_columns.rb', 'db/migrate/add_unit_columns'
|
20
|
+
migration_template 'db/migrate/003_add_value_types.rb', 'db/migrate/add_value_types'
|
21
|
+
end
|
22
|
+
|
23
|
+
def manifest
|
24
|
+
record do |m|
|
25
|
+
|
26
|
+
########################################
|
27
|
+
# persistence level configuration file #
|
28
|
+
########################################
|
29
|
+
|
30
|
+
# Get method from command line - default is metadata
|
31
|
+
method = args[0] || 'metadata'
|
32
|
+
# Make sure there is a config directory
|
33
|
+
m.directory File.join("config")
|
34
|
+
# Create persistence.yml file
|
35
|
+
m.template File.join("config","persistence.yml.erb"),
|
36
|
+
File.join("config","persistence.yml"),
|
37
|
+
:assigns => {:method => method}
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
File without changes
|
data/{generators → lib/generators}/persistence/templates/db/migrate/001_create_persistence_tables.rb
RENAMED
File without changes
|
File without changes
|
File without changes
|
data/spec/amee/db/config_spec.rb
CHANGED
data/spec/amee/db/{ongoing_calculation_persistence_support_spec.rb → persistence_support_spec.rb}
RENAMED
@@ -1,24 +1,24 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe AMEE::DataAbstraction::OngoingCalculation do
|
4
4
|
|
5
|
-
before(:
|
5
|
+
before(:each) do
|
6
6
|
populate_db
|
7
|
-
|
7
|
+
initialize_calculation_set
|
8
8
|
end
|
9
9
|
|
10
|
-
after(:
|
10
|
+
after(:each) do
|
11
11
|
AMEE::Db::Calculation.delete_all
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "find" do
|
15
|
-
|
15
|
+
|
16
16
|
before(:each) do
|
17
17
|
choose_mock
|
18
18
|
yaml_load_mock(:everything)
|
19
19
|
@reference = AMEE::Db::Calculation.find(:first).id
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
it "should create new ongoing calculation from db record" do
|
23
23
|
@db_calculation = AMEE::Db::Calculation.find :first
|
24
24
|
@ongoing_calculation = AMEE::DataAbstraction::OngoingCalculation.initialize_from_db_record @db_calculation
|
@@ -33,7 +33,7 @@ describe AMEE::DataAbstraction::OngoingCalculation do
|
|
33
33
|
hash[:profile_item_uid].should == "J38DY57SK591"
|
34
34
|
hash[:profile_uid].should be_nil
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
it "should create new ongoing calculation from db record with find" do
|
38
38
|
@ongoing_calculation = AMEE::DataAbstraction::OngoingCalculation.find :first
|
39
39
|
@ongoing_calculation.is_a?(AMEE::DataAbstraction::OngoingCalculation).should be_true
|
@@ -61,7 +61,7 @@ describe AMEE::DataAbstraction::OngoingCalculation do
|
|
61
61
|
hash[:profile_item_uid].should == "J38DY57SK591"
|
62
62
|
hash[:profile_uid].should be_nil
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
it "should create new ongoing calculation from db record with find and profile item uid" do
|
66
66
|
@ongoing_calculation = AMEE::DataAbstraction::OngoingCalculation.find :first, :conditions => {:profile_item_uid => "K588DH47SMN5"}
|
67
67
|
@ongoing_calculation.label.should == :electricity
|
@@ -89,7 +89,7 @@ describe AMEE::DataAbstraction::OngoingCalculation do
|
|
89
89
|
hash[:usage][:value].should_not be_nil
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
it "should create new ongoing calculation from db record with #find_by_type" do
|
94
94
|
@ongoing_calculation = AMEE::DataAbstraction::OngoingCalculation.find_by_type :first, :electricity
|
95
95
|
@ongoing_calculation.label.should == :electricity
|
@@ -103,7 +103,7 @@ describe AMEE::DataAbstraction::OngoingCalculation do
|
|
103
103
|
hash[:profile_item_uid].should == "J38DY57SK591"
|
104
104
|
hash[:profile_uid].should == nil
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
107
|
it "should create multiple new ongoing calculations from db record with #find_by_type" do
|
108
108
|
@ongoing_calculations = AMEE::DataAbstraction::OngoingCalculation.find_by_type :all, :electricity
|
109
109
|
@ongoing_calculations.class.should == AMEE::DataAbstraction::CalculationCollection
|
@@ -117,7 +117,7 @@ describe AMEE::DataAbstraction::OngoingCalculation do
|
|
117
117
|
hash[:usage][:value].should_not be_nil
|
118
118
|
end
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
it "should instantiate record at ongoing calc #db_calculation attribute" do
|
122
122
|
@ongoing_calculation = AMEE::DataAbstraction::OngoingCalculation.find :first
|
123
123
|
@ongoing_calculation.label.should == :electricity
|
@@ -125,51 +125,51 @@ describe AMEE::DataAbstraction::OngoingCalculation do
|
|
125
125
|
@ongoing_calculation.db_calculation.is_a?(AMEE::Db::Calculation).should be_true
|
126
126
|
@ongoing_calculation.db_calculation.id.should == @reference
|
127
127
|
end
|
128
|
-
|
128
|
+
|
129
129
|
it "should find assocaited db instance by id" do
|
130
130
|
@ongoing_calculation = AMEE::DataAbstraction::OngoingCalculation.find @reference
|
131
131
|
@ongoing_calculation.id.should == @reference
|
132
132
|
end
|
133
|
-
|
134
|
-
|
133
|
+
|
134
|
+
|
135
135
|
it "should give nil id, if not saved" do
|
136
|
-
|
137
|
-
|
136
|
+
Calculations[:electricity].begin_calculation.db_calculation.should be_nil
|
137
|
+
Calculations[:electricity].begin_calculation.id.should be_nil
|
138
138
|
end
|
139
139
|
end
|
140
|
-
|
140
|
+
|
141
141
|
describe "when storage method is :everything" do
|
142
|
-
|
142
|
+
|
143
143
|
before(:each) do
|
144
144
|
choose_mock
|
145
145
|
yaml_load_mock(:everything)
|
146
146
|
@ongoing_calculation = AMEE::DataAbstraction::OngoingCalculation.find :first
|
147
147
|
end
|
148
|
-
|
148
|
+
|
149
149
|
it "should find storage method" do
|
150
150
|
AMEE::DataAbstraction::OngoingCalculation.storage_method.should == :everything
|
151
151
|
end
|
152
|
-
|
152
|
+
|
153
153
|
it "should start off dirty" do
|
154
154
|
@ongoing_calculation.should be_dirty
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
it "should establish whether inputs to be stored" do
|
158
158
|
AMEE::DataAbstraction::OngoingCalculation.store_inputs?.should be_true
|
159
159
|
end
|
160
|
-
|
160
|
+
|
161
161
|
it "should establish whether outputs to be stored" do
|
162
162
|
AMEE::DataAbstraction::OngoingCalculation.store_outputs?.should be_true
|
163
163
|
end
|
164
|
-
|
164
|
+
|
165
165
|
it "should establish whether metadata to be stored" do
|
166
166
|
AMEE::DataAbstraction::OngoingCalculation.store_metadata?.should be_true
|
167
167
|
end
|
168
|
-
|
168
|
+
|
169
169
|
it "should return array of terms for storing which includes all terms" do
|
170
170
|
@ongoing_calculation.stored_terms.should == @ongoing_calculation.terms
|
171
171
|
end
|
172
|
-
|
172
|
+
|
173
173
|
it "should return hash with all terms" do
|
174
174
|
hash = @ongoing_calculation.to_hash
|
175
175
|
hash.is_a?(Hash).should be_true
|
@@ -177,7 +177,7 @@ describe AMEE::DataAbstraction::OngoingCalculation do
|
|
177
177
|
hash.keys.map!(&:to_s).sort!.should == [:profile_item_uid, :profile_uid, :calculation_type,
|
178
178
|
:co2, :usage, :country ].map!(&:to_s).sort!
|
179
179
|
end
|
180
|
-
|
180
|
+
|
181
181
|
it "should save all terms" do
|
182
182
|
record = @ongoing_calculation.db_calculation
|
183
183
|
# show that db record has values
|
@@ -197,41 +197,41 @@ describe AMEE::DataAbstraction::OngoingCalculation do
|
|
197
197
|
record.to_hash[:co2][:value].should == 1200
|
198
198
|
record.to_hash[:usage][:value].should == 6000
|
199
199
|
end
|
200
|
-
|
200
|
+
|
201
201
|
end
|
202
|
-
|
202
|
+
|
203
203
|
describe "when storage method is :metadata" do
|
204
|
-
|
204
|
+
|
205
205
|
before(:each) do
|
206
206
|
choose_mock
|
207
207
|
yaml_load_mock(:metadata)
|
208
208
|
@ongoing_calculation = AMEE::DataAbstraction::OngoingCalculation.find :first
|
209
209
|
end
|
210
|
-
|
210
|
+
|
211
211
|
it "should find storage method" do
|
212
212
|
AMEE::DataAbstraction::OngoingCalculation.storage_method.should == :metadata
|
213
213
|
end
|
214
|
-
|
214
|
+
|
215
215
|
it "should establish whether inputs to be stored" do
|
216
216
|
AMEE::DataAbstraction::OngoingCalculation.store_inputs?.should be_false
|
217
217
|
end
|
218
|
-
|
218
|
+
|
219
219
|
it "should establish whether outputs to be stored" do
|
220
220
|
AMEE::DataAbstraction::OngoingCalculation.store_outputs?.should be_false
|
221
221
|
end
|
222
|
-
|
222
|
+
|
223
223
|
it "should establish whether metadata to be stored" do
|
224
224
|
AMEE::DataAbstraction::OngoingCalculation.store_metadata?.should be_true
|
225
225
|
end
|
226
|
-
|
226
|
+
|
227
227
|
it "should start off dirty" do
|
228
228
|
@ongoing_calculation.should be_dirty
|
229
229
|
end
|
230
|
-
|
230
|
+
|
231
231
|
it "should return array of terms for storing which includes only metadata" do
|
232
232
|
@ongoing_calculation.stored_terms.should_not == @ongoing_calculation.terms
|
233
233
|
end
|
234
|
-
|
234
|
+
|
235
235
|
it "should return hash with only metadata terms" do
|
236
236
|
hash = @ongoing_calculation.to_hash
|
237
237
|
hash.is_a?(Hash).should be_true
|
@@ -239,7 +239,7 @@ describe AMEE::DataAbstraction::OngoingCalculation do
|
|
239
239
|
hash.keys.map!(&:to_s).sort!.should == [:profile_item_uid, :profile_uid,
|
240
240
|
:calculation_type ].map!(&:to_s).sort!
|
241
241
|
end
|
242
|
-
|
242
|
+
|
243
243
|
it "should save only metadata terms" do
|
244
244
|
record = @ongoing_calculation.db_calculation
|
245
245
|
# show that db record has values
|
@@ -254,7 +254,7 @@ describe AMEE::DataAbstraction::OngoingCalculation do
|
|
254
254
|
record.to_hash[:co2].should == nil
|
255
255
|
record.to_hash[:usage].should == nil
|
256
256
|
end
|
257
|
-
|
257
|
+
|
258
258
|
end
|
259
259
|
|
260
260
|
describe "when storage method is :outputs" do
|
@@ -311,7 +311,6 @@ describe AMEE::DataAbstraction::OngoingCalculation do
|
|
311
311
|
record.to_hash[:co2][:value].should == 1200
|
312
312
|
record.to_hash[:usage].should == nil
|
313
313
|
end
|
314
|
-
|
315
314
|
end
|
316
315
|
|
317
316
|
describe "saving" do
|
@@ -332,12 +331,11 @@ describe AMEE::DataAbstraction::OngoingCalculation do
|
|
332
331
|
# Saving should now return false, propogating errors from AR::Base
|
333
332
|
@ongoing_calculation.save.should eql false
|
334
333
|
end
|
335
|
-
|
336
334
|
end
|
337
335
|
|
338
336
|
describe "deleting calculation" do
|
339
337
|
|
340
|
-
before(:
|
338
|
+
before(:each) do
|
341
339
|
choose_mock
|
342
340
|
delete_mock
|
343
341
|
@ongoing_calculation = AMEE::DataAbstraction::OngoingCalculation.find :first
|
data/spec/amee/db/term_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,34 +1,22 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
3
|
-
require 'rspec_spinner'
|
2
|
+
require 'rspec'
|
4
3
|
require 'yaml'
|
5
4
|
require 'logger'
|
6
|
-
|
7
|
-
require 'amee-data-abstraction'
|
8
|
-
|
9
|
-
DB_CONFIG = YAML.load_file(File.dirname(__FILE__) + '/database.yml')
|
10
|
-
DB_MIGRATION = File.join(File.dirname(__FILE__), '..','generators','persistence','templates','db','migrate')
|
5
|
+
require 'amee-data-persistence'
|
11
6
|
|
12
|
-
|
13
|
-
|
14
|
-
File.dirname(__FILE__) + '/amee/fixtures'
|
15
|
-
end
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.mock_with :flexmock
|
16
9
|
end
|
17
10
|
|
18
|
-
|
19
|
-
require 'amee-data-persistence'
|
20
|
-
require 'amee/data_abstraction/ongoing_calculation_persistence_support'
|
11
|
+
RAILS_ROOT = '.'
|
21
12
|
|
22
|
-
|
23
|
-
|
13
|
+
DB_CONFIG = YAML.load_file(File.dirname(__FILE__) + '/database.yml')
|
14
|
+
DB_MIGRATION = File.join(File.dirname(__FILE__), '..','generators','persistence','templates','db','migrate')
|
24
15
|
|
16
|
+
ActiveRecord::Base.logger = Logger.new(File.open('database.log', 'a'))
|
25
17
|
ActiveRecord::Base.establish_connection(DB_CONFIG)
|
26
18
|
ActiveRecord::Migrator.up(DB_MIGRATION)
|
27
19
|
|
28
|
-
Spec::Runner.configure do |config|
|
29
|
-
config.mock_with :flexmock
|
30
|
-
end
|
31
|
-
|
32
20
|
def yaml_load_mock(method)
|
33
21
|
flexmock(YAML) do |mock|
|
34
22
|
mock.should_receive(:load_file).and_return('method' => method.to_s)
|
@@ -70,3 +58,28 @@ def populate_db
|
|
70
58
|
AMEE::Db::Calculation.new { |calc| calc.update_calculation! attr }
|
71
59
|
end
|
72
60
|
end
|
61
|
+
|
62
|
+
def initialize_calculation_set
|
63
|
+
eval "Calculations = AMEE::DataAbstraction::CalculationSet.new {
|
64
|
+
calculation{
|
65
|
+
name 'Electricity'
|
66
|
+
label :electricity
|
67
|
+
path '/business/energy/electricity/grid'
|
68
|
+
drill {
|
69
|
+
label :country
|
70
|
+
path 'country'
|
71
|
+
fixed 'Argentina'
|
72
|
+
}
|
73
|
+
profile {
|
74
|
+
label :usage
|
75
|
+
name 'Electricity Used'
|
76
|
+
path 'energyPerTime'
|
77
|
+
}
|
78
|
+
output {
|
79
|
+
label :co2
|
80
|
+
name 'Carbon Dioxide'
|
81
|
+
path :default
|
82
|
+
}
|
83
|
+
}
|
84
|
+
}"
|
85
|
+
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:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
|
-
- 1
|
8
7
|
- 2
|
9
8
|
- 0
|
10
|
-
|
9
|
+
- 0
|
10
|
+
version: 2.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- James Hetherington
|
@@ -18,27 +18,45 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2011-
|
21
|
+
date: 2011-09-28 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-data-abstraction
|
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:
|
33
|
+
hash: 3
|
32
34
|
segments:
|
33
|
-
-
|
34
|
-
-
|
35
|
-
version: "
|
35
|
+
- 2
|
36
|
+
- 0
|
37
|
+
version: "2.0"
|
38
|
+
requirement: *id001
|
39
|
+
- !ruby/object:Gem::Dependency
|
36
40
|
prerelease: false
|
41
|
+
name: activerecord
|
37
42
|
type: :runtime
|
38
|
-
|
43
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ~>
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
hash: 19
|
49
|
+
segments:
|
50
|
+
- 3
|
51
|
+
- 0
|
52
|
+
- 10
|
53
|
+
version: 3.0.10
|
54
|
+
requirement: *id002
|
39
55
|
- !ruby/object:Gem::Dependency
|
56
|
+
prerelease: false
|
40
57
|
name: bundler
|
41
|
-
|
58
|
+
type: :development
|
59
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
42
60
|
none: false
|
43
61
|
requirements:
|
44
62
|
- - ~>
|
@@ -49,12 +67,12 @@ dependencies:
|
|
49
67
|
- 0
|
50
68
|
- 0
|
51
69
|
version: 1.0.0
|
52
|
-
|
53
|
-
type: :development
|
54
|
-
requirement: *id002
|
70
|
+
requirement: *id003
|
55
71
|
- !ruby/object:Gem::Dependency
|
72
|
+
prerelease: false
|
56
73
|
name: jeweler
|
57
|
-
|
74
|
+
type: :development
|
75
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
58
76
|
none: false
|
59
77
|
requirements:
|
60
78
|
- - ~>
|
@@ -65,58 +83,28 @@ dependencies:
|
|
65
83
|
- 6
|
66
84
|
- 4
|
67
85
|
version: 1.6.4
|
68
|
-
|
69
|
-
type: :development
|
70
|
-
requirement: *id003
|
86
|
+
requirement: *id004
|
71
87
|
- !ruby/object:Gem::Dependency
|
72
|
-
name: rspec
|
73
|
-
version_requirements: &id004 !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
|
-
requirements:
|
76
|
-
- - "="
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
hash: 27
|
79
|
-
segments:
|
80
|
-
- 1
|
81
|
-
- 3
|
82
|
-
- 0
|
83
|
-
version: 1.3.0
|
84
88
|
prerelease: false
|
89
|
+
name: rspec
|
85
90
|
type: :development
|
86
|
-
requirement: *id004
|
87
|
-
- !ruby/object:Gem::Dependency
|
88
|
-
name: rcov
|
89
91
|
version_requirements: &id005 !ruby/object:Gem::Requirement
|
90
92
|
none: false
|
91
93
|
requirements:
|
92
|
-
- - "
|
94
|
+
- - "="
|
93
95
|
- !ruby/object:Gem::Version
|
94
|
-
hash:
|
96
|
+
hash: 23
|
95
97
|
segments:
|
98
|
+
- 2
|
99
|
+
- 6
|
96
100
|
- 0
|
97
|
-
version:
|
98
|
-
prerelease: false
|
99
|
-
type: :development
|
101
|
+
version: 2.6.0
|
100
102
|
requirement: *id005
|
101
103
|
- !ruby/object:Gem::Dependency
|
102
|
-
name: rspec_spinner
|
103
|
-
version_requirements: &id006 !ruby/object:Gem::Requirement
|
104
|
-
none: false
|
105
|
-
requirements:
|
106
|
-
- - "="
|
107
|
-
- !ruby/object:Gem::Version
|
108
|
-
hash: 21
|
109
|
-
segments:
|
110
|
-
- 1
|
111
|
-
- 1
|
112
|
-
- 3
|
113
|
-
version: 1.1.3
|
114
104
|
prerelease: false
|
115
|
-
type: :development
|
116
|
-
requirement: *id006
|
117
|
-
- !ruby/object:Gem::Dependency
|
118
105
|
name: flexmock
|
119
|
-
|
106
|
+
type: :development
|
107
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
120
108
|
none: false
|
121
109
|
requirements:
|
122
110
|
- - ">"
|
@@ -127,27 +115,39 @@ dependencies:
|
|
127
115
|
- 8
|
128
116
|
- 6
|
129
117
|
version: 0.8.6
|
118
|
+
requirement: *id006
|
119
|
+
- !ruby/object:Gem::Dependency
|
130
120
|
prerelease: false
|
121
|
+
name: rcov
|
131
122
|
type: :development
|
123
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
124
|
+
none: false
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
hash: 3
|
129
|
+
segments:
|
130
|
+
- 0
|
131
|
+
version: "0"
|
132
132
|
requirement: *id007
|
133
133
|
- !ruby/object:Gem::Dependency
|
134
|
-
|
134
|
+
prerelease: false
|
135
|
+
name: rdoc
|
136
|
+
type: :development
|
135
137
|
version_requirements: &id008 !ruby/object:Gem::Requirement
|
136
138
|
none: false
|
137
139
|
requirements:
|
138
|
-
- -
|
140
|
+
- - ">="
|
139
141
|
- !ruby/object:Gem::Version
|
140
|
-
hash:
|
142
|
+
hash: 3
|
141
143
|
segments:
|
142
|
-
-
|
143
|
-
|
144
|
-
- 5
|
145
|
-
version: 2.3.5
|
146
|
-
prerelease: false
|
147
|
-
type: :development
|
144
|
+
- 0
|
145
|
+
version: "0"
|
148
146
|
requirement: *id008
|
149
147
|
- !ruby/object:Gem::Dependency
|
148
|
+
prerelease: false
|
150
149
|
name: sqlite3
|
150
|
+
type: :development
|
151
151
|
version_requirements: &id009 !ruby/object:Gem::Requirement
|
152
152
|
none: false
|
153
153
|
requirements:
|
@@ -157,8 +157,6 @@ dependencies:
|
|
157
157
|
segments:
|
158
158
|
- 0
|
159
159
|
version: "0"
|
160
|
-
prerelease: false
|
161
|
-
type: :development
|
162
160
|
requirement: *id009
|
163
161
|
description: Part of the AMEEappkit, this gem provides storage and retrival of data provided by the amee-data-abstraction gem
|
164
162
|
email: help@amee.com
|
@@ -180,25 +178,21 @@ files:
|
|
180
178
|
- VERSION
|
181
179
|
- amee-data-persistence.gemspec
|
182
180
|
- amee-data-persistence.tmproj
|
183
|
-
- generators/persistence/persistence_generator.rb
|
184
|
-
- generators/persistence/templates/config/persistence.yml.erb
|
185
|
-
- generators/persistence/templates/db/migrate/001_create_persistence_tables.rb
|
186
|
-
- generators/persistence/templates/db/migrate/002_add_unit_columns.rb
|
187
|
-
- generators/persistence/templates/db/migrate/003_add_value_types.rb
|
188
|
-
- init.rb
|
189
181
|
- lib/amee-data-persistence.rb
|
190
182
|
- lib/amee/data_abstraction/calculation_collection.rb
|
191
|
-
- lib/amee/data_abstraction/
|
183
|
+
- lib/amee/data_abstraction/persistence_support.rb
|
192
184
|
- lib/amee/db/calculation.rb
|
193
185
|
- lib/amee/db/config.rb
|
194
186
|
- lib/amee/db/term.rb
|
195
|
-
-
|
187
|
+
- lib/generators/persistence/persistence_generator.rb
|
188
|
+
- lib/generators/persistence/templates/config/persistence.yml.erb
|
189
|
+
- lib/generators/persistence/templates/db/migrate/001_create_persistence_tables.rb
|
190
|
+
- lib/generators/persistence/templates/db/migrate/002_add_unit_columns.rb
|
191
|
+
- lib/generators/persistence/templates/db/migrate/003_add_value_types.rb
|
196
192
|
- spec/amee/db/calculation_spec.rb
|
197
193
|
- spec/amee/db/config_spec.rb
|
198
|
-
- spec/amee/db/
|
194
|
+
- spec/amee/db/persistence_support_spec.rb
|
199
195
|
- spec/amee/db/term_spec.rb
|
200
|
-
- spec/amee/fixtures/config/calculations/electricity.lock.rb
|
201
|
-
- spec/amee/fixtures/config/calculations/electricity.rb
|
202
196
|
- spec/database.yml
|
203
197
|
- spec/spec.opts
|
204
198
|
- spec/spec_helper.rb
|
@@ -232,7 +226,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
232
226
|
requirements: []
|
233
227
|
|
234
228
|
rubyforge_project:
|
235
|
-
rubygems_version: 1.
|
229
|
+
rubygems_version: 1.4.2
|
236
230
|
signing_key:
|
237
231
|
specification_version: 3
|
238
232
|
summary: Persistent storage of calculations performed against the AMEE API
|
@@ -1,97 +0,0 @@
|
|
1
|
-
# Copyright (C) 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
|
-
# :title: Class: PersistenceGenerator
|
5
|
-
|
6
|
-
# The global persistence storage level and migrations for the database tables can be
|
7
|
-
# generated the <i>PersistenceGenerator</i> class.
|
8
|
-
#
|
9
|
-
# The level of data storage for <i>AMEE::Db</i> can be configured to three
|
10
|
-
# distinct levels, representing the range of calculation terms which are
|
11
|
-
# persisted: all; outputs and metadata only; and metadata only.
|
12
|
-
#
|
13
|
-
# To set the global persistence level and generate migration files in /db/migrate,
|
14
|
-
# execute the following command line generator command:
|
15
|
-
#
|
16
|
-
# $ script/generate persistence <storage_level>
|
17
|
-
#
|
18
|
-
# where <storage_level> can be either 'everything', 'outputs' or 'metadata', e.g.,
|
19
|
-
#
|
20
|
-
# $ script/generate persistence everything
|
21
|
-
#
|
22
|
-
class PersistenceGenerator < Rails::Generator::Base
|
23
|
-
|
24
|
-
# Need to explicitly define the paths to both the templates directory and the
|
25
|
-
# standard application migrations directory. These are equivalent when using
|
26
|
-
# the #template method it is assumed therein that there is a mapping to the
|
27
|
-
# /templates directory for the generator templates (and from there the sub-
|
28
|
-
# paths are the same). This assumption is not valid when accessing the
|
29
|
-
# templates and the existing application migrations otherwise.
|
30
|
-
#
|
31
|
-
DEFAULT_MIGRATION_PATH = File.join("db/migrate")
|
32
|
-
TEMPLATE_MIGRATION_PATH = File.join(File.dirname(__FILE__),"templates",DEFAULT_MIGRATION_PATH)
|
33
|
-
|
34
|
-
def manifest
|
35
|
-
record do |m|
|
36
|
-
|
37
|
-
########################################
|
38
|
-
# persistence level configuration file #
|
39
|
-
########################################
|
40
|
-
|
41
|
-
# Get method from command line - default is metadata
|
42
|
-
method = args[0] || 'metadata'
|
43
|
-
# Make sure there is a config directory
|
44
|
-
m.directory File.join("config")
|
45
|
-
# Create persistence.yml file
|
46
|
-
m.template File.join("config","persistence.yml.erb"),
|
47
|
-
File.join("config","persistence.yml"),
|
48
|
-
:assigns => {:method => method}
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
#######################
|
53
|
-
# database migrations #
|
54
|
-
#######################
|
55
|
-
|
56
|
-
# Check db/migrate exists
|
57
|
-
m.directory DEFAULT_MIGRATION_PATH
|
58
|
-
# Create migrations if not already represented
|
59
|
-
migration_template_files.each_with_index do |file_name,index|
|
60
|
-
unless migration_exists? file_name
|
61
|
-
template_path = File.join(DEFAULT_MIGRATION_PATH,file_name)
|
62
|
-
# increment timestamp to differentiate files generated within same second
|
63
|
-
destination_file_name = file_name.gsub(/\d{3}/,"#{Time.now.strftime("%Y%m%d%I%M%S").to_i+index}")
|
64
|
-
destination_path = File.join(DEFAULT_MIGRATION_PATH,destination_file_name)
|
65
|
-
|
66
|
-
m.template template_path, destination_path
|
67
|
-
else
|
68
|
-
# print to stdout in standard migration reporting format
|
69
|
-
puts " exists migration content in template: #{file_name}"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
# Get names of all migration template files and sort them by version number
|
77
|
-
def migration_template_files
|
78
|
-
Dir.new(TEMPLATE_MIGRATION_PATH).entries.reject { |entry| File.directory? entry }.sort
|
79
|
-
end
|
80
|
-
|
81
|
-
# Check whether a migration already exists, by comparing the content of the
|
82
|
-
# migration template with any migrations which already exist in the
|
83
|
-
# applicaition's db/migrate directory. This is preferable to using file names
|
84
|
-
# since file names (1) have a time stamp and are therefore not consistent
|
85
|
-
# between separate instances of a file generation and (2) migration names may
|
86
|
-
# be changed in the future.
|
87
|
-
#
|
88
|
-
def migration_exists?(template)
|
89
|
-
template_content = File.read(File.join(TEMPLATE_MIGRATION_PATH,template))
|
90
|
-
|
91
|
-
Dir.new(DEFAULT_MIGRATION_PATH).entries.any? do |file|
|
92
|
-
next if File.directory?(file)
|
93
|
-
File.read(File.join(DEFAULT_MIGRATION_PATH,file)) == template_content
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + "/rails/init"
|
data/rails/init.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
|
2
|
-
# Authors:: James Hetherington, James Smith, Andrew Berkeley, George Palmer
|
3
|
-
# Copyright:: Copyright (c) 2011 AMEE UK Ltd
|
4
|
-
# License:: Permission is hereby granted, free of charge, to any person obtaining
|
5
|
-
# a copy of this software and associated documentation files (the
|
6
|
-
# "Software"), to deal in the Software without restriction, including
|
7
|
-
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
-
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
-
# permit persons to whom the Software is furnished to do so, subject
|
10
|
-
# to the following conditions:
|
11
|
-
#
|
12
|
-
# The above copyright notice and this permission notice shall be included
|
13
|
-
# in all copies or substantial portions of the Software.
|
14
|
-
#
|
15
|
-
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
-
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
-
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
-
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
-
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
|
-
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
|
-
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
-
#
|
23
|
-
|
24
|
-
require 'amee-data-abstraction'
|
25
|
-
require 'amee-data-persistence'
|
26
|
-
|
27
|
-
# include the <i>AMEE::DataAbstraction::PersistenceSupport</i> module within the
|
28
|
-
# <i>AMEE::DataAbstraction::OngoingCalculation</i> class providing interface
|
29
|
-
# methods for managing persistence of calculations.
|
30
|
-
#
|
31
|
-
::AMEE::DataAbstraction::OngoingCalculation.class_eval { include ::AMEE::DataAbstraction::PersistenceSupport }
|
@@ -1,30 +0,0 @@
|
|
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
|
-
|
@@ -1,20 +0,0 @@
|
|
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
|
-
}
|