module Opal::Config

Public Instance Methods

compiler_options() click to toggle source

@return [Hash] the configuration for Opal::Compiler

# File lib/opal/config.rb, line 55
def compiler_options
  compiler_options = {}
  config_options.each do |name, options|
    compiler_option_name = options.fetch(:compiler)
    compiler_options[compiler_option_name] = config.fetch(name)
  end
  compiler_options
end
config() click to toggle source

@return [Hash] the current configuration, defaults to default_config

# File lib/opal/config.rb, line 65
def config
  @config ||= default_config
end
default_config() click to toggle source

@return [Hash] the default configuration

# File lib/opal/config.rb, line 44
def default_config
  default_config = {}
  config_options.each do |name, options|
    default_value = options.fetch(:default)
    default_value = Proc === default_value ? default_value.call : default_value
    default_config[name] = default_value
  end
  default_config
end
reset!() click to toggle source

Resets the config to its default value

@return [void]

# File lib/opal/config.rb, line 72
def reset!
  @config = nil
end

Private Instance Methods

config_option(name, default_value, options = {}) click to toggle source

Defines a new configuration option

@param [String] name the option name @param [Object] default_value the option’s default value @!macro [attach] property

@!attribute [rw] $1
# File lib/opal/config.rb, line 21
def config_option(name, default_value, options = {})
  compiler      = options.fetch(:compiler_option, nil)
  valid_values  = options.fetch(:valid_values, [true, false])

  config_options[name] = {
    default: default_value,
    compiler: compiler
  }

  define_singleton_method(name) { config.fetch(name, default_value) }
  define_singleton_method("#{name}=") do |value|
    unless valid_values.any? { |valid_value| valid_value === value }
      raise ArgumentError, "Not a valid value for option #{self}.#{name}, provided #{value.inspect}. "\
                           "Must be #{valid_values.inspect} === #{value.inspect}"
    end

    config[name] = value
  end
end
config_options() click to toggle source
# File lib/opal/config.rb, line 11
def config_options
  @config_options ||= {}
end