class Retrospec::Config

Attributes

config_file[RW]

Public Class Methods

config_data(file) click to toggle source
# File lib/retrospec/config.rb, line 35
def self.config_data(file)
  new(file).config_data
end
new(file=default_config_file, opts={}) click to toggle source

we should be able to lookup where the user stores the config map so the user doesn't have to pass this info each time

# File lib/retrospec/config.rb, line 13
def initialize(file=default_config_file, opts={})
  setup_config_file(file)
end
plugin_context(config, plugin_name) click to toggle source

returns the configs that are only related to the plugin name

# File lib/retrospec/config.rb, line 40
def self.plugin_context(config, plugin_name)
  context = config.select {|k,v| k.downcase =~ /#{plugin_name}/ }
end

Public Instance Methods

config_data() click to toggle source

loads the config data into a ruby object

# File lib/retrospec/config.rb, line 31
def config_data
  @config_data ||= YAML.load_file(config_file) || {}
end
gem_dir() click to toggle source
# File lib/retrospec/config.rb, line 44
def gem_dir
  File.expand_path("../../../", __FILE__)
end
setup_config_file(file=nil) click to toggle source

create a blank yaml config file it file does not exist

# File lib/retrospec/config.rb, line 18
def setup_config_file(file=nil)
  if file.nil? or ! File.exists?(file)
    # config does not exist
    setup_config_dir
    dst_file = File.join(default_retrospec_dir, 'config.yaml')
    src_file = File.join(gem_dir,'config.yaml.sample')
    safe_copy_file(src_file, dst_file)
    file = dst_file
  end
  @config_file = file
end

Private Instance Methods

default_config_file() click to toggle source
# File lib/retrospec/config.rb, line 50
def default_config_file
  File.join(default_retrospec_dir, 'config.yaml')
end
setup_config_dir() click to toggle source
# File lib/retrospec/config.rb, line 54
def setup_config_dir
  FileUtils.mkdir_p(File.expand_path(default_retrospec_dir)) unless File.directory?(default_retrospec_dir)
end