class NeverBounce::CLI::UserConfig::FileContent

User's configuration file content. @see filename @see UserConfig @see CLI::Feature::BasicInitialize

Attributes

body[W]
body_hash[W]
env[W]
filename[W]

Public Instance Methods

[](k) click to toggle source

Fetch a value.

config_file["api_key"]
config_file[:api_key]   # Same as above.
# File lib/never_bounce/cli/user_config/file_content.rb, line 54
def [](k)
  body_hash[k.to_s]
end
body() click to toggle source

YAML configuration, source text. @!attribute body @return [String]

# 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() click to toggle source

YAML configuration, parsed. @!attribute body_hash @return [Hash]

# 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() click to toggle source

A copy of environment for read purposes. Default is ENV.to_h. @return [Hash]

# File lib/never_bounce/cli/user_config/file_content.rb, line 38
def env
  @env ||= ENV.to_h
end
filename() click to toggle source

Configuration filename. Default is $HOME/.neverbounce.yml. @return [String]

# File lib/never_bounce/cli/user_config/file_content.rb, line 44
def filename
  @filename ||= File.join(env["HOME"], ".neverbounce.yml")
end
has_key?(k) click to toggle source

true if key is set.

has_key?("api_key")
has_key?(:api_key)      # Identical to the previous one.
# File lib/never_bounce/cli/user_config/file_content.rb, line 62
def has_key?(k)
  body_hash.has_key? k.to_s
end