Class: Grape::Path

Inherits:
Object show all
Defined in:
lib/grape/path.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_path, namespace, settings) ⇒ Path



9
10
11
12
13
# File 'lib/grape/path.rb', line 9

def initialize(raw_path, namespace, settings)
  @raw_path = raw_path
  @namespace = namespace
  @settings = settings
end

Instance Attribute Details

#namespaceObject (readonly)

Returns the value of attribute namespace



7
8
9
# File 'lib/grape/path.rb', line 7

def namespace
  @namespace
end

#raw_pathObject (readonly)

Returns the value of attribute raw_path



7
8
9
# File 'lib/grape/path.rb', line 7

def raw_path
  @raw_path
end

#settingsObject (readonly)

Returns the value of attribute settings



7
8
9
# File 'lib/grape/path.rb', line 7

def settings
  @settings
end

Class Method Details

.prepare(raw_path, namespace, settings) ⇒ Object



3
4
5
# File 'lib/grape/path.rb', line 3

def self.prepare(raw_path, namespace, settings)
  Path.new(raw_path, namespace, settings).path_with_suffix
end

Instance Method Details

#has_namespace?Boolean



31
32
33
# File 'lib/grape/path.rb', line 31

def has_namespace?
  namespace && namespace.to_s =~ /^\S/ && namespace != '/'
end

#has_path?Boolean



35
36
37
# File 'lib/grape/path.rb', line 35

def has_path?
  raw_path && raw_path.to_s =~ /^\S/ && raw_path != '/'
end

#mount_pathObject



15
16
17
# File 'lib/grape/path.rb', line 15

def mount_path
  settings[:mount_path]
end

#pathObject



49
50
51
# File 'lib/grape/path.rb', line 49

def path
  Rack::Mount::Utils.normalize_path(parts.join('/'))
end

#path_with_suffixObject



53
54
55
# File 'lib/grape/path.rb', line 53

def path_with_suffix
  "#{path}#{suffix}"
end

#root_prefixObject



19
20
21
# File 'lib/grape/path.rb', line 19

def root_prefix
  split_setting(:root_prefix, '/')
end

#suffixObject



39
40
41
42
43
44
45
46
47
# File 'lib/grape/path.rb', line 39

def suffix
  if uses_specific_format?
    ''
  elsif !uses_path_versioning? || (has_namespace? || has_path?)
    '(.:format)'
  else
    '(/.:format)'
  end
end

#to_sObject



57
58
59
# File 'lib/grape/path.rb', line 57

def to_s
  path_with_suffix
end

#uses_path_versioning?Boolean



27
28
29
# File 'lib/grape/path.rb', line 27

def uses_path_versioning?
  !!(settings[:version] && settings[:version_options][:using] == :path)
end

#uses_specific_format?Boolean



23
24
25
# File 'lib/grape/path.rb', line 23

def uses_specific_format?
  !!(settings[:format] && settings[:content_types].size == 1)
end