Sha256: 8fc15380d02b7eb5f3ea6c0bec09e1cafa2369f4ec85811b179203a5d35fc609

Contents?: true

Size: 1.45 KB

Versions: 1

Compression:

Stored size: 1.45 KB

Contents

module ActiveMocker

  class Config
    class << self

      attr_accessor :model_dir,
                    :mock_dir,
                    :single_model_path,
                    :progress_bar,
                    :error_verbosity,
                    :disable_modules_and_constants
      #TODO add disable include/extend of modules
      #TODO disable scope methods
      #disable instance methods, class methods
      # can't disable attribute as of yet

      def model_base_classes=(val)
        @model_base_classes = val
      end

      def set(&block)
        load_defaults
        yield self
      end

      def load_defaults
        @error_verbosity               = 1
        @progress_bar                  = true
        @disable_modules_and_constants = false
        @model_dir                     = nil unless @model_dir
        @mock_dir                      = nil unless @mock_dir
        rails_defaults if Object.const_defined?('Rails')
      end

      def reset_all
        [:model_dir,
         :mock_dir,
         :log_location,
         :single_model_path,
         :progress_bar,
         :error_verbosity
        ].each { |ivar| instance_variable_set("@#{ivar}", nil) }
      end

      def rails_defaults
        @model_dir = File.join(Rails.root, 'app/models') unless @model_dir
        @mock_dir  = File.join(Rails.root, 'spec/mocks') unless @mock_dir
      end

      def progress_class
        @progress_bar ? Progress : NullProgress
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_mocker-2.0.0.beta1 lib/active_mocker/config.rb