Class: ApipieBindings::Route
- Inherits:
-
Object
- Object
- ApipieBindings::Route
- Defined in:
- lib/apipie_bindings/route.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
Instance Method Summary collapse
-
#initialize(path, method, description = "") ⇒ Route
constructor
A new instance of Route.
- #inspect ⇒ Object
- #params_in_path ⇒ Object
- #path(params = nil) ⇒ Object
- #to_s ⇒ Object
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
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/apipie_bindings/route.rb', line 5 def description @description end |
#method ⇒ Object (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
#inspect ⇒ Object
31 32 33 |
# File 'lib/apipie_bindings/route.rb', line 31 def inspect to_s end |
#params_in_path ⇒ Object
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? 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}", CGI.escape(param_value.to_s)) end end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/apipie_bindings/route.rb', line 27 def to_s "<Route #{@path}>" end |