Class: IgnoreIt::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ignore_it/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



8
9
10
11
12
# File 'lib/ignore_it/config.rb', line 8

def initialize
  $glob_settings = {}
  create_initial_config
  load_config
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/ignore_it/config.rb', line 6

def config
  @config
end

Instance Method Details

#create_initial_configObject

Create initial user config and folders in home directory



38
39
40
41
42
43
44
45
46
47
# File 'lib/ignore_it/config.rb', line 38

def create_initial_config
  Dir.chdir(Dir.home) do
    unless Dir.exist?(".ignore-it")
      Dir.mkdir(".ignore-it")
      Dir.mkdir(".ignore-it/gitignores")
      defaultConfig = File.read(find_gem_root + "/default_config.yml")
      File.write(".ignore-it/config.yml", defaultConfig)
    end
  end
end

#find_gem_rootObject

Find the gems install directory



32
33
34
35
# File 'lib/ignore_it/config.rb', line 32

def find_gem_root
  spec = Gem::Specification.find_by_name("ignore-it")
  spec.gem_dir
end

#load_configObject

Load user config from config directory



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ignore_it/config.rb', line 19

def load_config
  Dir.chdir(Dir.home) do
    if File.exist?(".ignore-it/config.yml")
      $glob_settings = YAML.load_file(".ignore-it/config.yml")
    else
      puts "Failed to load user config in ~/.ignore-it/config.yml".colorize(:red)
      puts "Defaulting...".colorize(:red)
      $glob_settings = YAML.load_file(find_gem_root + "/default_config.yml")
    end
  end
end


14
15
16
# File 'lib/ignore_it/config.rb', line 14

def print_config
  puts $glob_settings.to_yaml
end