Module: Insights::API::Common::ApplicationControllerMixins::RequestPath

Defined in:
lib/insights/api/common/application_controller_mixins/request_path.rb

Defined Under Namespace

Modules: ClassMethods Classes: RequestPathError

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(other) ⇒ Object



9
10
11
12
13
# File 'lib/insights/api/common/application_controller_mixins/request_path.rb', line 9

def self.included(other)
  other.extend(self::ClassMethods)

  other.before_action(:validate_primary_collection_id)
end

Instance Method Details

#request_pathObject



15
16
17
# File 'lib/insights/api/common/application_controller_mixins/request_path.rb', line 15

def request_path
  request.env["REQUEST_URI"]
end

#request_path_partsObject



19
20
21
22
23
24
# File 'lib/insights/api/common/application_controller_mixins/request_path.rb', line 19

def request_path_parts
  @request_path_parts ||= begin
    path, _query = request_path.split("?")
    path.match(/\/(?<full_version_string>v\d+.\d+)\/(?<primary_collection_name>\w+)(\/(?<primary_collection_id>[^\/]+)(\/(?<subcollection_name>\w+))?)?/)&.named_captures || {}
  end
end

#subcollection?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/insights/api/common/application_controller_mixins/request_path.rb', line 26

def subcollection?
  !!(request_path_parts["subcollection_name"] && request_path_parts["primary_collection_id"] && request_path_parts["primary_collection_name"])
end