Class: Praxis::Route
- Inherits:
-
Object
- Object
- Praxis::Route
- Defined in:
- lib/praxis/route.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
-
#path ⇒ Object
Returns the value of attribute path.
-
#prefixed_path ⇒ Object
Returns the value of attribute prefixed_path.
-
#verb ⇒ Object
Returns the value of attribute verb.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #describe ⇒ Object
- #example(params:, example_hash: {}) ⇒ Object
-
#initialize(verb, path, version = 'n/a', prefixed_path: nil, **options) ⇒ Route
constructor
A new instance of Route.
Constructor Details
#initialize(verb, path, version = 'n/a', prefixed_path: nil, **options) ⇒ Route
Returns a new instance of Route.
7 8 9 10 11 12 13 |
# File 'lib/praxis/route.rb', line 7 def initialize(verb, path, version = 'n/a', prefixed_path: nil, **) @verb = verb @path = path @version = version @options = @prefixed_path = prefixed_path end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/praxis/route.rb', line 5 def @options end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/praxis/route.rb', line 5 def path @path end |
#prefixed_path ⇒ Object
Returns the value of attribute prefixed_path.
5 6 7 |
# File 'lib/praxis/route.rb', line 5 def prefixed_path @prefixed_path end |
#verb ⇒ Object
Returns the value of attribute verb.
5 6 7 |
# File 'lib/praxis/route.rb', line 5 def verb @verb end |
#version ⇒ Object
Returns the value of attribute version.
5 6 7 |
# File 'lib/praxis/route.rb', line 5 def version @version end |
Instance Method Details
#describe ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/praxis/route.rb', line 30 def describe result = { verb: verb, path: path.to_s, version: version } result[:options] = if .any? result end |
#example(params:, example_hash: {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/praxis/route.rb', line 15 def example(params:, example_hash: {}) path_param_keys = path.named_captures.keys.collect(&:to_sym) param_attributes = params ? params.attributes : {} query_param_keys = param_attributes.keys - path_param_keys required_query_param_keys = query_param_keys.each_with_object([]) do |p, array| array << p if params.attributes[p].[:required] end path_params = example_hash.select { |k, _v| path_param_keys.include? k } # Let's generate the example only using required params, to avoid mixing incompatible parameters query_params = example_hash.select { |k, _v| required_query_param_keys.include? k } { verb: verb, url: path.(path_params.transform_values(&:to_s)), query_params: query_params } end |