Class: WinewooCore::Repositories::Mongo::Queries::WinewooUserQuery

Inherits:
UserQuery show all
Defined in:
lib/winewoo_core/repositories/mongo/queries/winewoo_user_query.rb

Instance Method Summary collapse

Methods inherited from UserQuery

#with_role

Methods inherited from WinewooQuery

#method_missing, #respond_to?, #respond_to_missing?

Constructor Details

#initializeWinewooUserQuery

Returns a new instance of WinewooUserQuery.



5
6
7
# File 'lib/winewoo_core/repositories/mongo/queries/winewoo_user_query.rb', line 5

def initialize
  super User.where(user_roles: :winewoo_user)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class WinewooCore::Repositories::Mongo::Queries::WinewooQuery

Instance Method Details

#for_interpro(interpro_id) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/winewoo_core/repositories/mongo/queries/winewoo_user_query.rb', line 20

def for_interpro(interpro_id)
  @relation = @relation
    .in(interpro_ids: BSON::ObjectId.from_string(interpro_id))

  block_given? ?
    @relation.each { |winewoo_user| yield winewoo_user } :
    self
end

#for_os(os) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/winewoo_core/repositories/mongo/queries/winewoo_user_query.rb', line 40

def for_os(os)
  @relation = @relation
    .where(device_os: os)

  block_given? ?
    @relation.each { |winewoo_user| yield winewoo_user } :
    self
end

#for_producer(producer_id) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/winewoo_core/repositories/mongo/queries/winewoo_user_query.rb', line 30

def for_producer(producer_id)
  @relation = @relation
    .in(producer_ids: BSON::ObjectId.from_string(producer_id))

  block_given? ?
    @relation.each { |winewoo_user| yield winewoo_user } :
    self
end

#for_winewooObject



10
11
12
13
14
15
16
17
# File 'lib/winewoo_core/repositories/mongo/queries/winewoo_user_query.rb', line 10

def for_winewoo
  @relation = @relation
    .where(:interpro_ids.with_size => 0)

  block_given? ?
    @relation.each { |winewoo_user| yield winewoo_user } :
    self
end

#with_email(email) ⇒ Object



61
62
63
# File 'lib/winewoo_core/repositories/mongo/queries/winewoo_user_query.rb', line 61

def with_email(email)
  @relation.where(email: email).first
end

#with_push_token(token = nil) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/winewoo_core/repositories/mongo/queries/winewoo_user_query.rb', line 50

def with_push_token(token = nil)
  @relation = token ?
    @relation.where(device_push_token: token) :
    @relation.where(:device_push_token.exists => true)

  block_given? ?
    @relation.each { |winewoo_user| yield winewoo_user } :
    self
end