Sha256: e5d138a6a859c0f55f7e44caa38b3cd37f14c0e5bdea3eb86383d31876df71d6

Contents?: true

Size: 754 Bytes

Versions: 25

Compression:

Stored size: 754 Bytes

Contents

module ApipieBindings

  class Route

    attr_reader :method, :description

    def initialize(path, method, description="")
      @path = path
      @method = method.downcase
      @description = description
    end

    def params_in_path
      @path.scan(/:([^\/]*)/).map { |m| m.first }
    end

    def path(params=nil)
      return @path if params.nil?

      path = params_in_path.inject(@path) do |p, param_name|
        param_value = (params[param_name.to_sym] or params[param_name.to_s]) or
          raise ArgumentError, "missing param '#{param_name}' in parameters"
        p.sub(":#{param_name}", URI.escape(param_value.to_s))
      end
    end

    def to_s
      "<Route #{@path}>"
    end

    def inspect
      to_s
    end

  end

end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
apipie-bindings-0.3.0 lib/apipie_bindings/route.rb
apipie-bindings-0.2.3 lib/apipie_bindings/route.rb
apipie-bindings-0.2.2 lib/apipie_bindings/route.rb
apipie-bindings-0.2.1 lib/apipie_bindings/route.rb
apipie-bindings-0.2.0 lib/apipie_bindings/route.rb
apipie-bindings-0.1.0 lib/apipie_bindings/route.rb
apipie-bindings-0.0.19 lib/apipie_bindings/route.rb
apipie-bindings-0.0.18 lib/apipie_bindings/route.rb
apipie-bindings-0.0.17 lib/apipie_bindings/route.rb
apipie-bindings-0.0.16 lib/apipie_bindings/route.rb
apipie-bindings-0.0.15 lib/apipie_bindings/route.rb
apipie-bindings-0.0.14 lib/apipie_bindings/route.rb
apipie-bindings-0.0.13 lib/apipie_bindings/route.rb
apipie-bindings-0.0.12 lib/apipie_bindings/route.rb
apipie-bindings-0.0.11 lib/apipie_bindings/route.rb
apipie-bindings-0.0.10 lib/apipie_bindings/route.rb
apipie-bindings-0.0.9 lib/apipie_bindings/route.rb
apipie-bindings-0.0.8 lib/apipie_bindings/route.rb
apipie-bindings-0.0.7 lib/apipie_bindings/route.rb
apipie-bindings-0.0.6 lib/apipie_bindings/route.rb