Module: Caprese::Versioning
- Extended by:
- ActiveSupport::Concern
- Included in:
- Controller, Controller, Serializer, Serializer
- Defined in:
- lib/caprese/concerns/versioning.rb
Instance Method Summary collapse
-
#namespaced_dot_path(suffix = nil) ⇒ String
Get full namespaced dot path (translations).
-
#namespaced_module(suffix = nil) ⇒ String
Get full namespaced module name of object (class).
-
#namespaced_name(suffix = nil) ⇒ String
Get full namespaced underscore name (routes).
-
#namespaced_path(suffix = nil) ⇒ String
Get full namespaced path (url).
-
#unnamespace(str) ⇒ String
Strips string to raw unnamespaced format regardless of input format.
-
#unversion(str) ⇒ String
Strips string to raw unversioned format regardless of input format.
-
#version_dot_path(suffix = nil) ⇒ String
Get version dot path (translations).
-
#version_module(suffix = nil) ⇒ String
Get versioned module name of object (class).
-
#version_name(suffix = nil) ⇒ String
Get versioned underscore name (routes).
-
#version_path(suffix = nil) ⇒ String
Get versioned path (url).
Instance Method Details
#namespaced_dot_path(suffix = nil) ⇒ String
Get full namespaced dot path (translations)
44 45 46 |
# File 'lib/caprese/concerns/versioning.rb', line 44 def namespaced_dot_path(suffix = nil) namespaced_module.downcase.split('::').push(suffix).reject(&:nil?).join('.') end |
#namespaced_module(suffix = nil) ⇒ String
Get full namespaced module name of object (class)
15 16 17 18 19 20 21 22 |
# File 'lib/caprese/concerns/versioning.rb', line 15 def namespaced_module(suffix = nil) mod = (self.is_a?(Class) ? self : self.class).name.deconstantize name = suffix || mod name = name.prepend("#{mod}::") unless suffix.nil? || (/^#{mod}::\.*/).match(suffix) name end |
#namespaced_name(suffix = nil) ⇒ String
Get full namespaced underscore name (routes)
56 57 58 |
# File 'lib/caprese/concerns/versioning.rb', line 56 def namespaced_name(suffix = nil) namespaced_module.downcase.split('::').push(suffix).reject(&:nil?).join('_') end |
#namespaced_path(suffix = nil) ⇒ String
Get full namespaced path (url)
32 33 34 |
# File 'lib/caprese/concerns/versioning.rb', line 32 def namespaced_path(suffix = nil) namespaced_module.downcase.split('::').push(suffix).reject(&:nil?).join('/') end |
#unnamespace(str) ⇒ String
Strips string to raw unnamespaced format regardless of input format
64 65 66 67 68 69 70 |
# File 'lib/caprese/concerns/versioning.rb', line 64 def unnamespace(str) str .remove(namespaced_module('')) .remove(namespaced_path('')) .remove(namespaced_name('')) .remove(namespaced_dot_path('')) end |
#unversion(str) ⇒ String
Strips string to raw unversioned format regardless of input format
132 133 134 135 136 137 138 |
# File 'lib/caprese/concerns/versioning.rb', line 132 def unversion(str) str .remove(version_module('')) .remove(version_path('')) .remove(version_name('')) .remove(version_dot_path('')) end |
#version_dot_path(suffix = nil) ⇒ String
Get version dot path (translations)
110 111 112 |
# File 'lib/caprese/concerns/versioning.rb', line 110 def version_dot_path(suffix = nil) version_module.downcase.split('::').push(suffix).reject(&:nil?).join('.') end |
#version_module(suffix = nil) ⇒ String
The difference between namespaced and versioned module names is that if an isolated_namespace is present, version_module will return a module name without the isolated namespace
Get versioned module name of object (class)
82 83 84 85 86 87 88 |
# File 'lib/caprese/concerns/versioning.rb', line 82 def version_module(suffix = nil) name = namespaced_module(suffix) name = name.gsub("#{Caprese.config.isolated_namespace}::", '') if Caprese.config.isolated_namespace name end |
#version_name(suffix = nil) ⇒ String
The difference between namespaced and versioned module names is that if an isolated_namespace is present, version_module will return a module name without the isolated namespace
Get versioned underscore name (routes)
124 125 126 |
# File 'lib/caprese/concerns/versioning.rb', line 124 def version_name(suffix = nil) version_module.downcase.split('::').push(suffix).reject(&:nil?).join('_') end |
#version_path(suffix = nil) ⇒ String
Get versioned path (url)
98 99 100 |
# File 'lib/caprese/concerns/versioning.rb', line 98 def version_path(suffix = nil) version_module.downcase.split('::').push(suffix).reject(&:nil?).join('/') end |