Class: Circus::LocalConfig

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

Instance Method Summary collapse

Constructor Details

#initialize(dir = '.') ⇒ LocalConfig

Returns a new instance of LocalConfig.



5
6
7
8
9
10
11
# File 'lib/circus/local_config.rb', line 5

def initialize(dir = '.')
  @dir = File.expand_path(dir)
  @is_new = true
  
  @store_fn = find_store_fn
  load!
end

Instance Method Details

#aliasesObject



17
18
19
# File 'lib/circus/local_config.rb', line 17

def aliases
  @state[:aliases] ||= {}
end

#boothsObject



13
14
15
# File 'lib/circus/local_config.rb', line 13

def booths
  @state[:booths] ||= {}
end

#load!Object



25
26
27
28
29
30
31
32
# File 'lib/circus/local_config.rb', line 25

def load!
  if File.exists? @store_fn
    @is_new = false
    @state = YAML::load(File.read(@store_fn))
  else
    @state = {}
  end
end

#new?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/circus/local_config.rb', line 21

def new?
  @is_new
end

#save!Object



34
35
36
37
38
39
40
# File 'lib/circus/local_config.rb', line 34

def save!
  FileUtils.mkdir_p(File.dirname(@store_fn))
  File.open(@store_fn, 'w') do |f|
    YAML::dump(@state, f)
  end
  @is_new = false
end