Sha256: 89fc295a729ccfd085c2c74d287ced7fad5e0aeef5ceba701c946b632e800603

Contents?: true

Size: 676 Bytes

Versions: 1

Compression:

Stored size: 676 Bytes

Contents

module Apiture
  class URI

    components = [:scheme, :host, :base_host, :subdomain, :base_path, :resource_path]

    attr_reader *components

    components.each do |comp|
      define_method "#{comp}=".to_sym do |v|
        instance_variable_set("@#{comp}", v)
        build_url
      end
    end

    def to_s
      build_url
    end

    protected

      def build_url
        host = if base_host && subdomain
                 [subdomain, base_host].join('.')
               else
                 self.host
               end
        [
          scheme,
          '://',
          host,
          base_path,
          resource_path
        ].join('')
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
apiture-0.2.0 lib/apiture/uri.rb