Class: Grape::Path
- Inherits:
-
Object
- Object
- Grape::Path
- Defined in:
- lib/grape/path.rb
Overview
Represents a path to an endpoint.
Defined Under Namespace
Classes: PartsCache
Instance Attribute Summary collapse
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#raw_path ⇒ Object
readonly
Returns the value of attribute raw_path.
-
#settings ⇒ Object
readonly
Returns the value of attribute settings.
Instance Method Summary collapse
-
#initialize(raw_path, namespace, settings) ⇒ Path
constructor
A new instance of Path.
- #mount_path ⇒ Object
- #namespace? ⇒ Boolean
- #path ⇒ Object
- #path? ⇒ Boolean
- #path_with_suffix ⇒ Object
- #root_prefix ⇒ Object
- #suffix ⇒ Object
- #to_s ⇒ Object
- #uses_path_versioning? ⇒ Boolean
- #uses_specific_format? ⇒ Boolean
Constructor Details
#initialize(raw_path, namespace, settings) ⇒ Path
Returns a new instance of Path.
8 9 10 11 12 |
# File 'lib/grape/path.rb', line 8 def initialize(raw_path, namespace, settings) @raw_path = raw_path @namespace = namespace @settings = settings end |
Instance Attribute Details
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
6 7 8 |
# File 'lib/grape/path.rb', line 6 def namespace @namespace end |
#raw_path ⇒ Object (readonly)
Returns the value of attribute raw_path.
6 7 8 |
# File 'lib/grape/path.rb', line 6 def raw_path @raw_path end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
6 7 8 |
# File 'lib/grape/path.rb', line 6 def settings @settings end |
Instance Method Details
#mount_path ⇒ Object
14 15 16 |
# File 'lib/grape/path.rb', line 14 def mount_path settings[:mount_path] end |
#namespace? ⇒ Boolean
34 35 36 |
# File 'lib/grape/path.rb', line 34 def namespace? namespace&.match?(/^\S/) && not_slash?(namespace) end |
#path ⇒ Object
52 53 54 |
# File 'lib/grape/path.rb', line 52 def path PartsCache[parts] end |
#path? ⇒ Boolean
38 39 40 |
# File 'lib/grape/path.rb', line 38 def path? raw_path&.match?(/^\S/) && not_slash?(raw_path) end |
#path_with_suffix ⇒ Object
56 57 58 |
# File 'lib/grape/path.rb', line 56 def path_with_suffix "#{path}#{suffix}" end |
#root_prefix ⇒ Object
18 19 20 |
# File 'lib/grape/path.rb', line 18 def root_prefix settings[:root_prefix] end |
#suffix ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/grape/path.rb', line 42 def suffix if uses_specific_format? "(.#{settings[:format]})" elsif !uses_path_versioning? || (namespace? || path?) '(.:format)' else '(/.:format)' end end |
#to_s ⇒ Object
60 61 62 |
# File 'lib/grape/path.rb', line 60 def to_s path_with_suffix end |
#uses_path_versioning? ⇒ Boolean
28 29 30 31 32 |
# File 'lib/grape/path.rb', line 28 def uses_path_versioning? return false unless settings.key?(:version) && settings[:version_options]&.key?(:using) settings[:version] && settings[:version_options][:using] == :path end |
#uses_specific_format? ⇒ Boolean
22 23 24 25 26 |
# File 'lib/grape/path.rb', line 22 def uses_specific_format? return false unless settings.key?(:format) && settings.key?(:content_types) settings[:format] && Array(settings[:content_types]).size == 1 end |