Module: Effective::EffectiveDatatable::Dsl::Scopes

Included in:
Datatable
Defined in:
app/models/effective/effective_datatable/dsl/scopes.rb

Instance Method Summary collapse

Instance Method Details

#scope(name, default = :klass_scope, options = {}, &block) ⇒ Object

Instance Methods inside the scopes do .. end block



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'app/models/effective/effective_datatable/dsl/scopes.rb', line 6

def scope(name, default = :klass_scope, options = {}, &block)
  if block_given?
    raise "You cannot use partial: ... with the block syntax" if options[:partial]
    options[:block] = block
  end

  if default == :klass_scope || default == { default: true }
    options[:klass_scope] = true
    default = (default == :klass_scope ? nil : true)
  end

  # This needs to be a {} not WithIndifferentAccess or rendering _scopes won't work correctly
  (@scopes ||= {})[name] = options.merge(default: default)
end