Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

changes for calc set

  • Loading branch information...
commit 8a85a713150d73a14f908b94a550da78e422fd03 1 parent d88fcf8
Andrew Berkeley spatchcock authored
2  lib/amee-data-persistence.rb
@@ -7,7 +7,7 @@
7 7 require 'amee-data-abstraction'
8 8
9 9 require 'amee/data_abstraction/calculation_collection'
10   -require 'amee/data_abstraction/persistence_support'
  10 +require 'amee/data_abstraction/ongoing_calculation_persistence_support'
11 11 require 'amee/db/calculation'
12 12 require 'amee/db/term'
13 13 require 'amee/db/config'
2  lib/amee/data_abstraction/persistence_support.rb → ...action/ongoing_calculation_persistence_support.rb
@@ -223,7 +223,7 @@ def initialize_from_db_record(record)
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)
2  lib/amee/db/config.rb
@@ -39,7 +39,7 @@ def store_everything?
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
6 spec/amee/db/persistence_support_spec.rb → ...b/ongoing_calculation_persistence_support_spec.rb
@@ -4,7 +4,7 @@
4 4
5 5 before(:each) do
6 6 populate_db
7   - initialize_calculation_set
  7 + AMEE::DataAbstraction::CalculationSet.find("electricity")
8 8 end
9 9
10 10 after(:each) do
@@ -133,8 +133,8 @@
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
25 spec/amee/fixtures/config/calculations/electricity.rb
... ... @@ -0,0 +1,25 @@
  1 +calculation {
  2 +
  3 + name 'Electricity'
  4 + label :electricity
  5 + path '/business/energy/electricity/grid'
  6 +
  7 + drill {
  8 + label :country
  9 + path 'country'
  10 + fixed 'Argentina'
  11 + }
  12 +
  13 + profile {
  14 + label :usage
  15 + name 'Electricity Used'
  16 + path 'energyPerTime'
  17 + }
  18 +
  19 + output {
  20 + label :co2
  21 + name 'Carbon Dioxide'
  22 + path 'default'
  23 + }
  24 +
  25 +}
33 spec/spec_helper.rb
@@ -8,7 +8,11 @@
8 8 config.mock_with :flexmock
9 9 end
10 10
11   -RAILS_ROOT = '.'
  11 +class Rails
  12 + def self.root
  13 + File.dirname(__FILE__) + '/amee/fixtures'
  14 + end
  15 +end
12 16
13 17 DB_CONFIG = YAML.load_file(File.dirname(__FILE__) + '/database.yml')
14 18 DB_MIGRATION = File.join(File.dirname(__FILE__), '..','lib','generators','persistence','templates','db','migrate')
@@ -57,29 +61,4 @@ def populate_db
57 61 [ calculation_one, calculation_two, calculation_three ].each do |attr|
58 62 AMEE::Db::Calculation.new { |calc| calc.update_calculation! attr }
59 63 end
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
  64 +end

0 comments on commit 8a85a71

Please sign in to comment.
Something went wrong with that request. Please try again.