Class: Exercism::Config

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/exercism/config.rb

Constant Summary collapse

PROPS_WITH_TEST_SUFFIX =
%i[
  dynamodb_tooling_jobs_table
  dynamodb_tooling_language_groups_table
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(data, aws_settings) ⇒ Config

Returns a new instance of Config.



8
9
10
11
# File 'lib/exercism/config.rb', line 8

def initialize(data, aws_settings)
  super(data)
  self.aws_settings = aws_settings
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/exercism/config.rb', line 13

def method_missing(name, *args)
  super.tap do |val|
    next unless val.nil?

    keys = to_h.keys
    raise NoMethodError, name unless keys.include?(name.to_s) || keys.include?(name.to_sym)
  end
end

Instance Method Details

#respond_to_missing?(*args) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/exercism/config.rb', line 22

def respond_to_missing?(*args)
  super
rescue NoMethodError
  false
end

#to_json(*_args) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/exercism/config.rb', line 35

def to_json(*_args)
  hash = to_h
  PROPS_WITH_TEST_SUFFIX.each do |prop|
    hash[prop] = send(prop)
  rescue NoMethodError
    # We don't want to show nil or empty string values in the JSON output
  end
  hash.to_json
end