Module: AmeeCarbonStore

Defined in:
lib/amee_rails_layer/amee_carbon_store.rb

Overview

Module that abstracts some common patterns for data storage/retrieval in AMEE. This is automatically included in ActiveRecord::Base object when used with Rails. See the gem README for more information on the application structure this gem assumes.

Classes that have the has_carbon_data_stored_in_amee decleartion require the following database columns:

  • name (string) - a name for the object, often set by user but can be assigned automatically

  • amee_profile_item_id (string) - the AMEE profile Item ID used to store the carbon data

  • carbon_output_cache (float) - the amount of carbon produced

  • units (string) - the units the amount field is in

  • amount (float) - the amount of the thing being recorded, eg 6 (kg), 9 (litres)

  • amee_profile (string) - optional. The amee profile identifier under which all the data is stored. Although this field is optional, either this or profile_id is required

  • profile_id (integer) - optional. Used when the model belongs_to a parent that has the amee_profile identifier. Name is changed according to the :profile option passed into the has_carbon_data_stored_in_amee. Although this field is optional, either this or amee_profile is required.

  • repetitions (integer) - optional. Used when the model object is composed of several repetitions - for example 6 x 3 miles would make the repetitions 6

  • start_date (date) - optional. Used in combination with the has_date_range option on has_carbon_data_stored_in_amee to store the start date for the data

  • end_date (date) - optional. Used in combination with the has_date_range option on has_carbon_data_stored_in_amee to store the end date for the data

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



25
26
27
# File 'lib/amee_rails_layer/amee_carbon_store.rb', line 25

def self.included(base)
  base.extend ClassMethods
end