Sha256: 729540487a89b1b7ebe7012ea51f2fb3df7bec13705255daf844c3b2a28cfc21

Contents?: true

Size: 755 Bytes

Versions: 1

Compression:

Stored size: 755 Bytes

Contents

module Wikipedia
  class Configuration
    DEFAULT = {
      protocol: 'https',
      domain: 'en.wikipedia.org',
      path: 'w/api.php',
      user_agent: 'wikipedia-client/1.7 (https://github.com/kenpratt/wikipedia-client)'
    }.freeze

    def initialize(configuration = DEFAULT)
      DEFAULT.merge(configuration).each { |args| send(*args) }
    end

    def [](directive)
      send(directive)
    end

    def self.directives(*directives)
      directives.each do |directive|
        define_method directive do |*args|
          return instance_variable_get("@#{directive}") if args.empty?

          instance_variable_set("@#{directive}", args.first)
        end
      end
    end

    directives :protocol, :domain, :path, :user_agent
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
wikipedia-client-1.15.0 lib/wikipedia/configuration.rb