Class: MongoidEmbedFinder::Projectors::Base

Inherits:
Struct
  • Object
show all
Defined in:
lib/mongoid_embed_finder/projectors/base.rb

Direct Known Subclasses

Single

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#queryObject

Returns the value of attribute query

Returns:

  • (Object)

    the current value of query



3
4
5
# File 'lib/mongoid_embed_finder/projectors/base.rb', line 3

def query
  @query
end

#relationObject

Returns the value of attribute relation

Returns:

  • (Object)

    the current value of relation



3
4
5
# File 'lib/mongoid_embed_finder/projectors/base.rb', line 3

def relation
  @relation
end

Instance Method Details

#operatorObject

Raises:

  • (NotImplementedError)


14
15
16
# File 'lib/mongoid_embed_finder/projectors/base.rb', line 14

def operator
  raise NotImplementedError, "operator needs to be overriden"
end

#project(fields = []) ⇒ Object



8
9
10
11
12
# File 'lib/mongoid_embed_finder/projectors/base.rb', line 8

def project(fields = [])
  projection_with_fields = projection.merge(include_fields(fields))
  query.scope_parent(projection)
  query.execute.select(projection_with_fields)
end

#projectionObject



4
5
6
# File 'lib/mongoid_embed_finder/projectors/base.rb', line 4

def projection
  { relation.key => { operator => query.child_criteria.selector }}
end