module Insights::API::Common::ApplicationControllerMixins::RequestPath
Public Class Methods
included(other)
click to toggle source
# 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
Public Instance Methods
request_path()
click to toggle source
# File lib/insights/api/common/application_controller_mixins/request_path.rb, line 15 def request_path request.env["REQUEST_URI"] end
request_path_parts()
click to toggle source
# 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?()
click to toggle source
# 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
Private Instance Methods
id_regexp()
click to toggle source
# File lib/insights/api/common/application_controller_mixins/request_path.rb, line 32 def id_regexp self.class.send(:id_regexp, request_path_parts["primary_collection_name"]) end
validate_primary_collection_id()
click to toggle source
# File lib/insights/api/common/application_controller_mixins/request_path.rb, line 36 def validate_primary_collection_id id = request_path_parts["primary_collection_id"] return if id.blank? raise RequestPathError, "ID is invalid" unless id.match(id_regexp) end