class Conferrable::Entry

This class builds on the basic concepts of Configuration and FileBasedConfiguration. It allows the ability to define a “configuration store”.

Attributes

default_folder[W]
filenames[R]
key[R]

Public Class Methods

default_file(name) click to toggle source
# File lib/conferrable/entry.rb, line 21
def default_file(name)
  File.join(default_folder, "#{name}.yml.erb")
end
default_folder() click to toggle source
# File lib/conferrable/entry.rb, line 17
def default_folder
  @default_folder || File.join('.', 'config')
end
new(key, filenames: nil) click to toggle source
# File lib/conferrable/entry.rb, line 28
def initialize(key, filenames: nil)
  raise ArgumentError, 'key is required' unless key && key.to_s.length.positive?

  @key        = key.to_s
  @filenames  = filenames
end

Public Instance Methods

all() click to toggle source
# File lib/conferrable/entry.rb, line 45
def all
  load!

  @configuration&.all || {}
end
filenames=(filenames) click to toggle source
# File lib/conferrable/entry.rb, line 35
def filenames=(filenames)
  protected!

  @filenames = filenames
end
loaded?() click to toggle source
# File lib/conferrable/entry.rb, line 41
def loaded?
  @loaded || false
end
loaded_filenames() click to toggle source
# File lib/conferrable/entry.rb, line 51
def loaded_filenames
  @configuration&.loaded_filenames || []
end

Private Instance Methods

load!() click to toggle source
# File lib/conferrable/entry.rb, line 65
def load!
  if loaded?
    @configuration.load!
    return
  end

  names = Array(filenames).flatten

  names = [self.class.default_file(key)] if names.length.zero?

  @configuration = FileBasedConfiguration.new(names)

  loaded!
end
loaded!() click to toggle source
# File lib/conferrable/entry.rb, line 61
def loaded!
  @loaded = true
end
protected!() click to toggle source
# File lib/conferrable/entry.rb, line 57
def protected!
  raise ArgumentError, "#{key} config store has been re-configured after load." if loaded?
end