lib/her/model/orm.rb
# Define the default scope for the model
#
# @example
#   class User
#     include Her::Model
#
#     default_scope lambda { where(:admin => 1) }
#   enc
#
#   User.all # Called via GET "/users?admin=1"
#   User.new.admin # => 1
Define the default scope for the model
Define the default scope for the model
def default_scope(block = nil)
          @_her_default_scope ||= (!respond_to?(:default_scope) && superclass.respond_to?(:default_scope)) ? superclass.default_scope : scoped
          @_her_default_scope = @_her_default_scope.instance_exec(&block) unless block.nil?
          @_her_default_scope
        end
def default_scope ( block = nil ) @_her_default_scope ||= ( ! respond_to? ( :default_scope ) && superclass . respond_to? ( :default_scope ) ) ? superclass . default_scope : scoped @_her_default_scope = @_her_default_scope . instance_exec ( & block ) unless block . nil? @_her_default_scope end
Define the default scope for the model
Define the default scope for the model
block
<not_specific>
example
class User include Her::Model default_scope lambda { where(:admin => 1) } enc User.all # Called via GET "/users?admin=1" User.new.admin # => 1
class User include Her :: Model default_scope lambda { where ( : admin = > 1 ) } enc User . all # Called via GET " / users?admin = 1 " User . new . admin # = > 1