Sha256: a7dc23c7526966d1f3840baf84b604b229336c2417674d362830742daf7d17ac

Contents?: true

Size: 1.52 KB

Versions: 17

Compression:

Stored size: 1.52 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(context = nil)
        scopes.detect do |scope|
          if scope.default_block.is_a?(Proc)
            render_in_context(context, scope.default_block)
          else
            scope.default_block
          end
        end
      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)
        default_options = { show_count: namespace.scopes_show_count }
        options = default_options.merge(args.extract_options!)
        title = args[0] rescue nil
        method = args[1] rescue nil

        options[:localizer] ||= ActiveAdmin::Localizers.resource(self)
        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

        scope
      end

    end
  end
end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/activeadmin-2.9.0/lib/active_admin/resource/scopes.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/activeadmin-2.9.0/lib/active_admin/resource/scopes.rb
activeadmin-2.9.0 lib/active_admin/resource/scopes.rb
activeadmin-2.8.1 lib/active_admin/resource/scopes.rb
activeadmin-2.8.0 lib/active_admin/resource/scopes.rb
activeadmin-2.7.0 lib/active_admin/resource/scopes.rb
activeadmin-2.6.1 lib/active_admin/resource/scopes.rb
activeadmin-2.6.0 lib/active_admin/resource/scopes.rb
activeadmin-2.5.0 lib/active_admin/resource/scopes.rb
activeadmin-2.4.0 lib/active_admin/resource/scopes.rb
activeadmin-2.3.1 lib/active_admin/resource/scopes.rb
activeadmin-2.3.0 lib/active_admin/resource/scopes.rb
activeadmin-2.2.0 lib/active_admin/resource/scopes.rb
activeadmin-2.1.0 lib/active_admin/resource/scopes.rb
activeadmin-2.0.0 lib/active_admin/resource/scopes.rb
activeadmin-2.0.0.rc2 lib/active_admin/resource/scopes.rb
activeadmin-2.0.0.rc1 lib/active_admin/resource/scopes.rb