Module: Buildkite::Env::Fallback

Included in:
Buildkite::Env
Defined in:
lib/buildkite/env.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *_args, &_block) ⇒ Object

rubocop:disable Style/MethodMissingSuper



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/buildkite/env.rb', line 9

def method_missing(method_name, *_args, &_block) # rubocop:disable Style/MethodMissingSuper
  env_name = "#{PREFIX}#{method_name.to_s.gsub(/\?\z/, '').upcase}"

  if method_name.to_s.end_with?('?')
    @env.key?(env_name)
  elsif @env.key?(env_name)
    @env.fetch(env_name)
  else
    raise NoMethodError, "undefined method #{method_name} for #{self} because ENV[\"#{env_name}\"] is not defined"
  end
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/buildkite/env.rb', line 21

def respond_to_missing?(method_name, include_private = false)
  method_name.to_s.end_with?('?') || @env.key?("#{PREFIX}#{method_name.upcase}") || super
end