Skip to content

Latest commit

 

History

History
22 lines (17 loc) · 474 Bytes

Scopes.md

File metadata and controls

22 lines (17 loc) · 474 Bytes

Scope allow you to pack the logic of your filters into easy-to-read helpers:

class User
  include Clear::Model
  #...
  scope(admin){ where{admin == true} }
end

User.query.admin.each do |u|
end

Scope can be chained during the building of your query, and can have parameters:

  # in your model definition
  scope(with_roles){ |*roles| where{ role.in?(roles) } }
  
  User.query.admin.with_roles("publisher", "supplier").each do |u|
    #...