Class: Boothby::YAMLReader

Inherits:
Object
  • Object
show all
Defined in:
lib/boothby/yaml_reader.rb

Overview

Read YAML files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ YAMLReader

Returns a new instance of YAMLReader.



8
9
10
# File 'lib/boothby/yaml_reader.rb', line 8

def initialize(name)
  @filename = file_name(name)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, **kwargs, &block) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/boothby/yaml_reader.rb', line 17

def method_missing(method_name, *args, **kwargs, &block)
  env = kwargs.delete(:environment) || kwargs.delete(:env)
  return get(method_name, environment: env) unless env.nil?

  cfg = full_config.fetch(method_name, nil)
  return (args.empty? ? cfg : cfg.dig(*args)) unless cfg.nil?

  get(method_name) || super
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



6
7
8
# File 'lib/boothby/yaml_reader.rb', line 6

def filename
  @filename
end

Instance Method Details

#get(*attributes, environment: nil) ⇒ Object



12
13
14
15
# File 'lib/boothby/yaml_reader.rb', line 12

def get(*attributes, environment: nil)
  environment ||= Rails.env
  full_config[environment].dig(*attributes) || full_config.dig(*attributes)
end