Sha256: 54b05653f52761207916d160c5ee026c109184738f627d2fa80206c2d9056d95

Contents?: true

Size: 762 Bytes

Versions: 93

Compression:

Stored size: 762 Bytes

Contents

# frozen_string_literal: true

module Motor
  module ApiQuery
    module ApplyScope
      module_function

      def call(rel, scope)
        return rel if scope.blank?

        scope_symbol = scope.to_sym

        if rel.klass.defined_scopes.include?(scope_symbol)
          rel.public_send(scope_symbol)
        else
          apply_filter_scope(rel, scope)
        end
      end

      def apply_filter_scope(rel, scope)
        configs = Motor::Resource.find_by(name: rel.klass.name.underscore)

        return rel unless configs

        scope_configs = configs.preferences[:scopes].find { |s| s[:name] == scope }

        return rel unless scope_configs

        ApiQuery::Filter.call(rel, scope_configs[:preferences][:filter])
      end
    end
  end
end

Version data entries

93 entries across 93 versions & 1 rubygems

Version Path
motor-admin-0.2.39 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.38 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.37 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.36 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.35 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.34 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.33 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.32 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.31 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.30 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.29 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.28 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.27 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.26 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.25 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.24 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.23 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.22 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.21 lib/motor/api_query/apply_scope.rb
motor-admin-0.2.20 lib/motor/api_query/apply_scope.rb