Class: Okapi::ExplicitConfig

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ ExplicitConfig

Returns a new instance of ExplicitConfig.



23
24
25
# File 'lib/okapi/cli/config.rb', line 23

def initialize(filename)
  @filename = filename
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



21
22
23
# File 'lib/okapi/cli/config.rb', line 21

def filename
  @filename
end

Instance Method Details

#checkfile!(force) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/okapi/cli/config.rb', line 36

def checkfile!(force)
  if !File.exists?(@filename)
    if force
      yield false
    else
      raise Okapi::ConfigurationError, "Unable to find configuration file '#{@filename}`"
    end
  else
    yield true
  end
end

#read!(force: false) ⇒ Object



30
31
32
33
34
# File 'lib/okapi/cli/config.rb', line 30

def read!(force: false)
  checkfile!(force) do |exists|
    exists ? File.read(@filename) : ""
  end
end

#write!(&block) ⇒ Object



26
27
28
# File 'lib/okapi/cli/config.rb', line 26

def write!(&block)
  File.open(@filename, "w", &block)
end