Class: Afterlife::Repo::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/afterlife/repo/config.rb

Overview

Reads configuration from the repo, either from YML or from the repo instance methods

Constant Summary collapse

Error =
Class.new StandardError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Config

Returns a new instance of Config.



16
17
18
# File 'lib/afterlife/repo/config.rb', line 16

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



10
11
12
# File 'lib/afterlife/repo/config.rb', line 10

def path
  @path
end

Class Method Details

.read(path, &block) ⇒ Object



12
13
14
# File 'lib/afterlife/repo/config.rb', line 12

def self.read(path, &block)
  new(path).read(&block)
end

Instance Method Details

#read(&block) ⇒ Object

rubocop:disable Metrics/MethodLength



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/afterlife/repo/config.rb', line 20

def read(&block) # rubocop:disable Metrics/MethodLength
  case from_yml
  when Hash
    yield(JSON.generate(from_yml))
  when Array
    from_yml.each(&block)
  when String, Symbol
    yield(from_yml)
  else
    fail Error, "No config with path '#{path}'" unless repo_method?

    yield(repo.public_send(repo_method))
  end
end