Sha256: d6f0495f74f95b0f01149eaa22b47dc0ec91212d864b571c6b58eab84e77471f

Contents?: true

Size: 868 Bytes

Versions: 6

Compression:

Stored size: 868 Bytes

Contents

module ActiveAdmin
  class Scope

    attr_reader :name, :scope_method, :id, :scope_block

    # Create a Scope
    #
    # Examples:
    #
    #   Scope.new(:published)
    #   # => Scope with name 'Published' and scope method :published
    #
    #   Scope.new('Published', :public)
    #   # => Scope with name 'Published' and scope method :public
    #
    #   Scope.new('Published') { |articles| articles.where(:published => true) }
    #   # => Scope with name 'Published' using a block to scope
    #
    def initialize(name, method = nil, &block)
      @name = name.to_s.titleize
      @scope_method = method
      # Scope ':all' means no scoping
      @scope_method ||= name.to_sym unless name.to_sym == :all
      @id = @name.gsub(' ', '').underscore
      if block_given?
        @scope_method = nil
        @scope_block = block
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
andrewroth_activeadmin-0.3.4 lib/active_admin/scope.rb
activeadmin-0.3.4 lib/active_admin/scope.rb
activeadmin-0.3.3 lib/active_admin/scope.rb
activeadmin-0.3.2 lib/active_admin/scope.rb
activeadmin-0.3.1 lib/active_admin/scope.rb
activeadmin-0.3.0 lib/active_admin/scope.rb