Class: Okapi::ExplicitConfig
- Inherits:
-
Object
- Object
- Okapi::ExplicitConfig
- Defined in:
- lib/okapi/cli/config.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
Instance Method Summary collapse
- #checkfile!(force) ⇒ Object
-
#initialize(filename) ⇒ ExplicitConfig
constructor
A new instance of ExplicitConfig.
- #read!(force: false) ⇒ Object
- #write!(&block) ⇒ Object
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
#filename ⇒ Object (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 |