Class: MagicScopes::ScopesBuilder
- Inherits:
-
Object
- Object
- MagicScopes::ScopesBuilder
- Includes:
- StandardScopes
- Defined in:
- lib/magic_scopes/scopes_builder.rb
Constant Summary collapse
- STANDARD_OPTIONS =
[:std, :in, :ex]
- MAGIC_SCOPES =
{ boolean: [:is, :not, :with, :without], integer: [:with, :without, :eq, :ne, :gt, :gte, :lt, :lte, :by, :by_desc], float: [:with, :without, :lt, :gt, :by, :by_desc], string: [:with, :without, :eq, :ne, :by, :by_desc, :like, :not_like, :ilike, :not_ilike], association: [:for, :not_for] }
Instance Method Summary collapse
- #generate_scopes ⇒ Object
- #generate_standard_scopes ⇒ Object
-
#initialize(model, *attrs) ⇒ ScopesBuilder
constructor
A new instance of ScopesBuilder.
Constructor Details
#initialize(model, *attrs) ⇒ ScopesBuilder
Returns a new instance of ScopesBuilder.
21 22 23 24 25 26 27 28 29 |
# File 'lib/magic_scopes/scopes_builder.rb', line 21 def initialize(model, *attrs) @model = model @options = attrs..symbolize_keys @attributes_with_scopes = extract_attributes_with_scopes @attributes = make_attributes(attrs) @is_attributes_passed = attrs.present? || @attributes_with_scopes.present? @needed_scopes = make_needed_scopes end |
Instance Method Details
#generate_scopes ⇒ Object
35 36 37 |
# File 'lib/magic_scopes/scopes_builder.rb', line 35 def generate_scopes generate_explicitly_passed_scopes.merge(generate_implicitly_specified_scopes) end |
#generate_standard_scopes ⇒ Object
31 32 33 |
# File 'lib/magic_scopes/scopes_builder.rb', line 31 def generate_standard_scopes (@options[:std] || STANDARD_SCOPES).each { |scope_type| send("#{scope_type}_scope") } end |