Sha256: 7c0c04caaeeb721d72641944bb9a4393243cc3073c5bd18d092ed3a2f2bdf2ee

Contents?: true

Size: 1.13 KB

Versions: 5

Compression:

Stored size: 1.13 KB

Contents

##
# ConfigHelper
#
module ConfigHelper
  def self.included(base)
    base.extend ClassMethods
  end

  #------------------
  
  def config(options)
    @_config_reset = NPR.config
    NPR.config.merge(options)
  end

  #------------------
  
  def reset_config
    NPR.instance_variable_set(:@config, @_config_reset)
  end
  
  #------------------
  
  def config!(options)
    config = NPR::Configuration.new(options)
    NPR.instance_variable_set(:@config, config)
  end
  
  #------------------
  
  def clear_config
    NPR.instance_variable_set(:@config, nil)
  end
  
  #------------------
  
  module ClassMethods
    # Merge the options into whatever the config
    # currently is, and reset it to its previous
    # state after.
    def config(options)
      before :all do
        config(options)
      end
        
      after :all do
        reset_config
      end
    end
    
    #--------------------
    # Set the config to ONLY the provided options,
    # and set to nil after.
    def config!(options)
      before :all do
        config!(options)
      end
        
      after :all do
        reset_config
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
npr-1.2.0 spec/support/config_helper.rb
npr-1.1.0 spec/support/config_helper.rb
npr-0.1.2 spec/support/config_helper.rb
npr-0.1.1 spec/support/config_helper.rb
npr-0.1.0 spec/support/config_helper.rb