Module: Elasticsearch::Persistence::Scoping::Named::ClassMethods

Defined in:
lib/elasticsearch/persistence/scoping/named.rb

Constant Summary collapse

BLACKLISTED_CLASS_METHODS =
%w(private public protected allocate new name parent superclass)

Instance Method Summary collapse

Instance Method Details

#all(options = {}) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/elasticsearch/persistence/scoping/named.rb', line 8

def all(options={})
  if current_scope
    current_scope.clone
  else
    default_scoped.size(10000)
  end
end

#default_scopedObject

:nodoc:



16
17
18
# File 'lib/elasticsearch/persistence/scoping/named.rb', line 16

def default_scoped # :nodoc:
  relation.merge(build_default_scope)
end

#scope(name, body, &block) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/elasticsearch/persistence/scoping/named.rb', line 31

def scope(name, body, &block)
  if dangerous_class_method?(name)
    raise ArgumentError, "You tried to define a scope named \"#{name}\" " \
      "on the model \"#{self.name}\", but Active Record already defined " \
      "a class method with the same name."
  end

  extension = Module.new(&block) if block

  singleton_class.send(:define_method, name) do |*args|
    scope = all.scoping { body.call(*args) }
    scope = scope.extending(extension) if extension

    scope || all
  end
end

#scope_attributesObject

Collects attributes from scopes that should be applied when creating an AR instance for the particular class this is called on.



22
23
24
# File 'lib/elasticsearch/persistence/scoping/named.rb', line 22

def scope_attributes # :nodoc:
  all.scope_for_create
end

#scope_attributes?Boolean

Are there default attributes associated with this scope?

Returns:

  • (Boolean)


27
28
29
# File 'lib/elasticsearch/persistence/scoping/named.rb', line 27

def scope_attributes? # :nodoc:
  current_scope || default_scopes.any?
end