Class: Detom::LocalConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/detom/local_config.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



31
32
33
34
35
# File 'lib/detom/local_config.rb', line 31

def method_missing(name, *args, &block)
  super unless handle?(name)

  handle(name, *args)
end

Instance Method Details

#load!Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/detom/local_config.rb', line 5

def load!
  return if @store

  if Dir.exist? ".detom"
    raise "Found .detom but it is a directory. Are you running `detom set` in your home directory?\n`detom set` should be run in the root of a project folder"
  end

  if File.exist? ".detom"
    @store = YAML.load File.read(".detom")
  else
    @store = {}
  end
end

#load_from!(config) ⇒ Object



19
20
21
22
# File 'lib/detom/local_config.rb', line 19

def load_from!(config)
  @store ||= {}
  @store.merge! config
end

#save!Object



24
25
26
27
28
29
# File 'lib/detom/local_config.rb', line 24

def save!
  @store.keys.each {|key| @store.delete(key) if @store[key].nil? }

  File.open(".detom", "w") {|file| file.write YAML.dump(@store) }
  puts "New config: #{@store}"
end