Sha256: 763f28d5a0309e68ce617852c6f182d379aa33bb094f7ff7b17352bf81be9a28

Contents?: true

Size: 1.21 KB

Versions: 59

Compression:

Stored size: 1.21 KB

Contents

module ActiveAdmin
  class Resource
    module Scopes

      # Return an array of scopes for this resource
      def scopes
        @scopes ||= []
      end

      # Returns a scope for this object by its identifier
      def get_scope_by_id(id)
        id = id.to_s
        scopes.find{|s| s.id == id }
      end

      def default_scope
        @default_scope
      end

      # Create a new scope object for this resource.
      # If you want to internationalize the scope name, you can add
      # to your i18n files a key like "active_admin.scopes.scope_method".
      def scope(*args, &block)
        options = args.extract_options!
        title = args[0] rescue nil
        method = args[1] rescue nil

        scope = ActiveAdmin::Scope.new(title, method, options, &block)

        # Finds and replaces a scope by the same name if it already exists
        existing_scope_index = scopes.index{|existing_scope| existing_scope.id == scope.id }
        if existing_scope_index
          scopes.delete_at(existing_scope_index)
          scopes.insert(existing_scope_index, scope)
        else
          self.scopes << scope
        end

        @default_scope = scope if options[:default]

        scope
      end

    end
  end
end

Version data entries

59 entries across 59 versions & 3 rubygems

Version Path
lalala-4.0.0.dev.141 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.136 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.135 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.134 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.133 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.132 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.131 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.129 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.128 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.126 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.125 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.124 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.123 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.118 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.116 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.114 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.113 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.111 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.109 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb
lalala-4.0.0.dev.107 vendor/deps/active_admin/lib/active_admin/resource/scopes.rb