Sha256: 40b10edefe424ca4c88a8f854c5230fe2f4a37c4c89849f769e9ed3c0711dead

Contents?: true

Size: 671 Bytes

Versions: 82

Compression:

Stored size: 671 Bytes

Contents

module ActiveAdmin
  module ScopeChain
    # Scope an ActiveRecord::Relation chain
    #
    # Example:
    #   scope_chain(Scope.new(:published), Article)
    #   # => Article.published
    #
    # @param scope The <ActiveAdmin::Scope> we want to scope on
    # @param chain The ActiveRecord::Relation chain or ActiveRecord::Base class to scope
    # @return <ActiveRecord::Relation or ActiveRecord::Base> The scoped relation chain
    #
    def scope_chain(scope, chain)
      if scope.scope_method
        chain.send(scope.scope_method)
      elsif scope.scope_block
        instance_exec chain, &scope.scope_block
      else
        chain
      end
    end
  end
end

Version data entries

82 entries across 82 versions & 7 rubygems

Version Path
activeadmin-0.3.1 lib/active_admin/helpers/scope_chain.rb
activeadmin-0.3.0 lib/active_admin/helpers/scope_chain.rb