Sha256: 8b50ffa0eb7bcb1b5b0676ac9a6483d737787d3898286d5ed3ba622fd3da107c

Contents?: true

Size: 1.06 KB

Versions: 20

Compression:

Stored size: 1.06 KB

Contents

##
# Modified from Sinatra
# Provide flexible configuration for Midori Server
module Configurable
  # Sets an option to the given value.
  # @param [Symbol] option the name of config
  # @param [Object] value value to the name
  # @param [Boolean] read_only Generate option= method or not
  # @return [nil] nil
  def set(option, value = (not_set = true), read_only = false)
    raise ArgumentError if not_set

    setter = proc { |val| set option, val }
    getter = proc { value }

    define_singleton("#{option}=", setter) unless read_only
    define_singleton(option, getter)
    define_singleton("#{option}?", "!!#{option}") unless method_defined? "#{option}?"

    self
  end

  # Dynamically defines a method on settings.
  # @param [String] name method name
  # @param [Proc] content method content
  # @return [nil] nil
  private def define_singleton(name, content = Proc.new)
    singleton_class.class_eval do
      undef_method(name) if method_defined? name
      String === content ? class_eval("def #{name}() #{content}; end") : define_method(name, &content)
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
midori.rb-0.9.0 lib/midori/core_ext/configurable.rb
midori.rb-0.8.0 lib/midori/core_ext/configurable.rb
midori.rb-0.7.1 lib/midori/core_ext/configurable.rb
midori.rb-0.7.0 lib/midori/core_ext/configurable.rb
midori.rb-0.6.0 lib/midori/core_ext/configurable.rb
midori.rb-0.5.4 lib/midori/core_ext/configurable.rb
midori.rb-0.5.3.1 lib/midori/core_ext/configurable.rb
midori.rb-0.5.3 lib/midori/core_ext/configurable.rb
midori.rb-0.5.2 lib/midori/core_ext/configurable.rb
midori.rb-0.5.1 lib/midori/core_ext/configurable.rb
midori.rb-0.5.0 lib/midori/core_ext/configurable.rb
midori.rb-0.4.4.1 lib/midori/core_ext/configurable.rb
midori.rb-0.4.4 lib/midori/core_ext/configurable.rb
midori.rb-0.4.3 lib/midori/core_ext/configurable.rb
em-midori-0.4.3 lib/midori/core_ext/configurable.rb
em-midori-0.4.2.1 lib/midori/core_ext/configurable.rb
em-midori-0.4.2 lib/midori/core_ext/configurable.rb
em-midori-0.4.1.1 lib/midori/core_ext/configurable.rb
em-midori-0.4.1 lib/midori/core_ext/configurable.rb
em-midori-0.4.0 lib/midori/core_ext/configurable.rb