Class: Retrospec::Config

Inherits:
Object
  • Object
show all
Includes:
Plugins::V1, Plugins::V1::ModuleHelpers
Defined in:
lib/retrospec/config.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Plugins::V1::ModuleHelpers

#create_content, #default_retrospec_dir, #notify, #overwrite?, #overwrite_all, #overwrite_enabled?, #prompt_for_overwrite, #retrospec_file?, #retrospec_repos_dir, #safe_copy_file, #safe_create_directory_files, #safe_create_file, #safe_create_module_files, #safe_create_symlink, #safe_create_template_file, #safe_mkdir, #safe_move_file, #safe_touch, #should_create?, #sync_file?

Constructor Details

#initialize(file = default_config_file, opts = {}) ⇒ Config

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


13
14
15
# File 'lib/retrospec/config.rb', line 13

def initialize(file=default_config_file, opts={})
  setup_config_file(file)
end

Instance Attribute Details

#config_fileObject

Returns the value of attribute config_file


9
10
11
# File 'lib/retrospec/config.rb', line 9

def config_file
  @config_file
end

Class Method Details

.config_data(file) ⇒ Object


35
36
37
# File 'lib/retrospec/config.rb', line 35

def self.config_data(file)
  new(file).config_data
end

.plugin_context(config, plugin_name) ⇒ Object

returns the configs that are only related to the plugin name


40
41
42
# File 'lib/retrospec/config.rb', line 40

def self.plugin_context(config, plugin_name)
  context = config.select {|k,v| k.downcase =~ /#{plugin_name}/ }
end

Instance Method Details

#config_dataObject

loads the config data into a ruby object


31
32
33
# File 'lib/retrospec/config.rb', line 31

def config_data
  @config_data ||= YAML.load_file(config_file) || {}
end

#gem_dirObject


44
45
46
# File 'lib/retrospec/config.rb', line 44

def gem_dir
  File.expand_path("../../../", __FILE__)
end

#setup_config_file(file = nil) ⇒ Object

create a blank yaml config file it file does not exist


18
19
20
21
22
23
24
25
26
27
28
# 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