Sha256: f2ffac18319446e8d857bf67623408c29073ba40a030c37a0e6828db59f94e49

Contents?: true

Size: 971 Bytes

Versions: 1

Compression:

Stored size: 971 Bytes

Contents

require "gem_configurator/version"
require 'active_support/inflector'

module GemConfigurator

  attr_reader :settings
  
  private
  
  def config_path
    config_file_name = "#{self.class.to_s.underscore}.yml"
    if using_rails? && File.exists?(Rails.root.join("config",config_file_name))
      Rails.root.join("config",config_file_name)
    elsif File.exists?("config/#{config_file_name}")
      File.path("config/#{config_file_name}")
    else
      nil
    end
  end
  
  def configure
    raw_settings = parse_yaml(config_path())
    environment = using_rails? ? Rails.env : 'development'

    if raw_settings
      @settings = raw_settings[environment]
    else
      @settings = {}          
    end

    if self.respond_to?(:default_settings,true)
      @settings = default_settings.merge(@settings)
    else
      @settings
    end
  end
  
  def parse_yaml(path)
    path ? YAML.load_file(path) : nil
  end
  
  def using_rails?
    defined?(Rails)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gem_configurator-1.1.0 lib/gem_configurator.rb