Class: Grape::Path
- Inherits:
-
Object
- Object
- Grape::Path
- Defined in:
- lib/grape/path.rb
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.
Class Method Summary collapse
Instance Method Summary collapse
- #has_namespace? ⇒ Boolean
- #has_path? ⇒ Boolean
-
#initialize(raw_path, namespace, settings) ⇒ Path
constructor
A new instance of Path.
- #mount_path ⇒ Object
- #path ⇒ Object
- #path_with_suffix ⇒ Object
- #root_prefix ⇒ Object
- #suffix ⇒ Object
- #to_s ⇒ Object
- #uses_path_versioning? ⇒ Boolean
Constructor Details
#initialize(raw_path, namespace, settings) ⇒ Path
Returns a new instance of Path.
10 11 12 13 14 |
# File 'lib/grape/path.rb', line 10 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.
8 9 10 |
# File 'lib/grape/path.rb', line 8 def namespace @namespace end |
#raw_path ⇒ Object (readonly)
Returns the value of attribute raw_path.
8 9 10 |
# File 'lib/grape/path.rb', line 8 def raw_path @raw_path end |
#settings ⇒ Object (readonly)
Returns the value of attribute settings.
8 9 10 |
# File 'lib/grape/path.rb', line 8 def settings @settings end |
Class Method Details
.prepare(raw_path, namespace, settings) ⇒ Object
4 5 6 |
# File 'lib/grape/path.rb', line 4 def self.prepare(raw_path, namespace, settings) Path.new(raw_path, namespace, settings).path_with_suffix end |
Instance Method Details
#has_namespace? ⇒ Boolean
28 29 30 |
# File 'lib/grape/path.rb', line 28 def has_namespace? namespace && namespace.to_s =~ /^\S/ && namespace != '/' end |
#has_path? ⇒ Boolean
32 33 34 |
# File 'lib/grape/path.rb', line 32 def has_path? raw_path && raw_path.to_s =~ /^\S/ && raw_path != '/' end |
#mount_path ⇒ Object
16 17 18 |
# File 'lib/grape/path.rb', line 16 def mount_path split_setting(:mount_path, '/') end |
#path ⇒ Object
44 45 46 |
# File 'lib/grape/path.rb', line 44 def path Rack::Mount::Utils.normalize_path(parts.join('/')) end |
#path_with_suffix ⇒ Object
48 49 50 |
# File 'lib/grape/path.rb', line 48 def path_with_suffix "#{path}#{suffix}" end |
#root_prefix ⇒ Object
20 21 22 |
# File 'lib/grape/path.rb', line 20 def root_prefix split_setting(:root_prefix, '/') end |
#suffix ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/grape/path.rb', line 36 def suffix if !uses_path_versioning? || (has_namespace? || has_path?) '(.:format)' else '(/.:format)' end end |
#to_s ⇒ Object
52 53 54 |
# File 'lib/grape/path.rb', line 52 def to_s path_with_suffix end |
#uses_path_versioning? ⇒ Boolean
24 25 26 |
# File 'lib/grape/path.rb', line 24 def uses_path_versioning? settings[:version] && settings[:version_options][:using] == :path end |