Sha256: 9d4b0346f0735e2d1956031b1a743e035638583246d2aa482c615269e17a87d7

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

# Copyright (C) 2011 AMEE UK Ltd. - http://www.amee.com
# Released as Open Source Software under the BSD 3-Clause license. See LICENSE.txt for details.

# :title: Class: AMEE::Db::BaseConfig

require 'singleton'

module AMEE
  module Db
    
    # A singleton class for configuration. Automatically initialised on first use
    # Use like so:
    #
    #   AMEE::Db::Config.instance.store_everything?
    #
    # Separated into BaseConfig and Config to allow unit testing of singleton.
    #
    class BaseConfig
    
      def initialize
        # Default is metadata
        @storage_method = load_storage_method || :metadata
      end
            
      attr_reader :storage_method

      def store_metadata?
        [:metadata, :outputs, :everything].include? storage_method
      end

      def store_outputs?
        [:outputs, :everything].include? storage_method
      end

      def store_everything?
        [:everything].include? storage_method
      end

      private
      
      def load_storage_method
        m = YAML.load_file("#{::Rails.root}/config/persistence.yml")['method'].to_sym
        raise "amee-data-persistence: Invalid storage method" unless [:metadata, :outputs, :everything].include? m
        m
      end

    end
    
    class Config < BaseConfig
      include Singleton
    end
      
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
amee-data-persistence-2.3.0 lib/amee/db/config.rb
amee-data-persistence-2.2.1 lib/amee/db/config.rb
amee-data-persistence-2.2.0 lib/amee/db/config.rb