module Datadog::Configuration::Options::ClassMethods

Class behavior for a configuration object with options

Public Instance Methods

options() click to toggle source
# File lib/ddtrace/configuration/options.rb, line 16
def options
  @options ||= begin
    # Allows for class inheritance of option definitions
    superclass <= Options ? superclass.options.dup : OptionDefinitionSet.new
  end
end

Protected Instance Methods

option(name, meta = {}, &block) click to toggle source
# File lib/ddtrace/configuration/options.rb, line 25
def option(name, meta = {}, &block)
  builder = OptionDefinition::Builder.new(name, meta, &block)
  options[name] = builder.to_definition.tap do
    # Resolve and define helper functions
    helpers = default_helpers(name).merge(builder.helpers)
    define_helpers(helpers)
  end
end

Private Instance Methods

default_helpers(name) click to toggle source
# File lib/ddtrace/configuration/options.rb, line 36
def default_helpers(name)
  option_name = name.to_sym

  {
    option_name.to_sym => proc do
      get_option(option_name)
    end,
    "#{option_name}=".to_sym => proc do |value|
      set_option(option_name, value)
    end
  }
end
define_helpers(helpers) click to toggle source
# File lib/ddtrace/configuration/options.rb, line 49
def define_helpers(helpers)
  helpers.each do |name, block|
    next unless block.is_a?(Proc)
    define_method(name, &block)
  end
end