Class: IgnoreIt::Config
- Inherits:
-
Object
- Object
- IgnoreIt::Config
- Defined in:
- lib/ignore_it/config.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Instance Method Summary collapse
-
#create_initial_config ⇒ Object
Create initial user config and folders in home directory.
-
#find_gem_root ⇒ Object
Find the gems install directory.
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#load_config ⇒ Object
Load user config from config directory.
- #print_config ⇒ Object
Constructor Details
#initialize ⇒ Config
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
#config ⇒ Object
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_config ⇒ Object
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_root ⇒ Object
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_config ⇒ Object
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 |
#print_config ⇒ Object
14 15 16 |
# File 'lib/ignore_it/config.rb', line 14 def print_config puts $glob_settings.to_yaml end |