Class: ApipieBindings::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/apipie_bindings/route.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, method, description = "") ⇒ Route

Returns a new instance of Route


7
8
9
10
11
# File 'lib/apipie_bindings/route.rb', line 7

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

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description


5
6
7
# File 'lib/apipie_bindings/route.rb', line 5

def description
  @description
end

#methodObject (readonly)

Returns the value of attribute method


5
6
7
# File 'lib/apipie_bindings/route.rb', line 5

def method
  @method
end

Instance Method Details

#inspectObject


31
32
33
# File 'lib/apipie_bindings/route.rb', line 31

def inspect
  to_s
end

#params_in_pathObject


13
14
15
# File 'lib/apipie_bindings/route.rb', line 13

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

#path(params = nil) ⇒ Object


17
18
19
20
21
22
23
24
25
# File 'lib/apipie_bindings/route.rb', line 17

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

#to_sObject


27
28
29
# File 'lib/apipie_bindings/route.rb', line 27

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