Module: MagicScopes::EqualityScopes

Included in:
NumericScopesGenerator, StringScopesGenerator
Defined in:
lib/magic_scopes/scopes_generators/mixins/equality_scopes.rb

Instance Method Summary collapse

Instance Method Details

#eq(name) ⇒ Object



7
8
9
# File 'lib/magic_scopes/scopes_generators/mixins/equality_scopes.rb', line 7

def eq(name)
  scope name || "#{@attr}_eq", eq_scope
end

#ne(name) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/magic_scopes/scopes_generators/mixins/equality_scopes.rb', line 15

def ne(name)
  scope name || "#{@attr}_ne", ->(*vals) {
    raise ArgumentError, "No argument for for_#{@attr} scope" if vals.empty?
    sql = "#{@key} " << (vals.size == 1 && !vals[0].is_a?(Array) ? '!= ?' : 'NOT IN (?)') << " OR #{@key} IS NULL"
    where(sql, vals.flatten)
  }
end

#with(name) ⇒ Object



3
4
5
# File 'lib/magic_scopes/scopes_generators/mixins/equality_scopes.rb', line 3

def with(name)
  scope name || "with_#{@attr}", eq_scope
end

#without(name) ⇒ Object



11
12
13
# File 'lib/magic_scopes/scopes_generators/mixins/equality_scopes.rb', line 11

def without(name)
  scope name || "without_#{@attr}", -> { where("#{@key} IS NULL") }
end