Class: NeverBounce::CLI::UserConfig::FileContent
- Inherits:
-
Object
- Object
- NeverBounce::CLI::UserConfig::FileContent
- Defined in:
- lib/never_bounce/cli/user_config/file_content.rb
Overview
User’s configuration file content.
Instance Attribute Summary collapse
-
#body ⇒ String
YAML configuration, source text.
-
#body_hash ⇒ Hash
YAML configuration, parsed.
-
#env ⇒ Hash
A copy of environment for read purposes.
-
#filename ⇒ String
Configuration filename.
Instance Method Summary collapse
-
#[](k) ⇒ Object
Fetch a value.
-
#has_key?(k) ⇒ Boolean
true
if key is set.
Instance Attribute Details
#body ⇒ String
YAML configuration, source text.
21 22 23 24 25 26 27 |
# File 'lib/never_bounce/cli/user_config/file_content.rb', line 21 def body @body ||= begin File.read(filename) rescue Errno::ENOENT # Missing file is okay, let other exceptions manifest. "" end end |
#body_hash ⇒ Hash
YAML configuration, parsed.
32 33 34 |
# File 'lib/never_bounce/cli/user_config/file_content.rb', line 32 def body_hash @body_hash ||= body.to_s.empty?? {} : YAML.load(body) end |
#env ⇒ Hash
A copy of environment for read purposes. Default is ENV.to_h
.
38 39 40 |
# File 'lib/never_bounce/cli/user_config/file_content.rb', line 38 def env @env ||= ENV.to_h end |
#filename ⇒ String
Configuration filename. Default is $HOME/.neverbounce.yml
.
44 45 46 |
# File 'lib/never_bounce/cli/user_config/file_content.rb', line 44 def filename @filename ||= File.join(env["HOME"], ".neverbounce.yml") end |
Instance Method Details
#[](k) ⇒ Object
Fetch a value.
config_file["api_key"]
config_file[:api_key] # Same as above.
54 55 56 |
# File 'lib/never_bounce/cli/user_config/file_content.rb', line 54 def [](k) body_hash[k.to_s] end |
#has_key?(k) ⇒ Boolean
true
if key is set.
has_key?("api_key")
has_key?(:api_key) # Identical to the previous one.
62 63 64 |
# File 'lib/never_bounce/cli/user_config/file_content.rb', line 62 def has_key?(k) body_hash.has_key? k.to_s end |