File: in_config_wrapper.rb

package info (click to toggle)
ruby-aruba 2.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 968 kB
  • sloc: javascript: 6,850; ruby: 4,010; makefile: 5
file content (33 lines) | stat: -rw-r--r-- 640 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# frozen_string_literal: true

# Aruba
module Aruba
  # In config wrapper
  #
  # Used to make the configuration read only if one needs to access an
  # configuration option from with `Aruba::Config`.
  #
  # @private
  class InConfigWrapper
    attr_reader :config
    private :config

    def initialize(config)
      @config = config.dup
    end

    def method_missing(name, *args)
      if config.key? name
        raise ArgumentError, 'Options take no argument' if args.any?

        config[name]
      else
        super
      end
    end

    def respond_to_missing?(name, _include_private)
      config.key? name
    end
  end
end