Class: WinewooCore::Repositories::Mongo::Queries::WineQuery

Inherits:
WinewooQuery
  • Object
show all
Defined in:
lib/winewoo_core/repositories/mongo/queries/wine_query.rb

Instance Method Summary collapse

Methods inherited from WinewooQuery

#method_missing, #respond_to?, #respond_to_missing?

Constructor Details

#initialize(relation = Wine) ⇒ WineQuery

Returns a new instance of WineQuery.



4
5
6
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 4

def initialize(relation = Wine)
  super relation
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

#count_all_vintagesObject



32
33
34
35
36
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 32

def count_all_vintages
  @relation.all.inject(0) do |total, wine|
    total += wine.vintages.length
  end
end

#draftsObject



149
150
151
152
153
154
155
156
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 149

def drafts
  @relation = @relation
    .where(:status.ne => :published)

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

#from_interpro(interpro_id) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 17

def from_interpro(interpro_id)
  @relation = @relation
    .where(interpro_id: interpro_id)

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

#from_producer(producer_id) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 8

def from_producer(producer_id)
  @relation = @relation
    .where(producer_id: producer_id)

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

#officialsObject



158
159
160
161
162
163
164
165
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 158

def officials
  @relation = @relation
    .where(unofficial: false)

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

#percented_by(lower, higher) ⇒ Object



130
131
132
133
134
135
136
137
138
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 130

def percented_by(lower, higher)
  @relation = @relation
    .where(:computed_percent.gt => lower)
    .where(:computed_percent.lte => higher)

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

#publishedObject



140
141
142
143
144
145
146
147
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 140

def published
  @relation = @relation
    .where(:status => :published)

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

#unofficialsObject



167
168
169
170
171
172
173
174
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 167

def unofficials
  @relation = @relation
    .where(unofficial: true)

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

#with_appelation(appelation) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 78

def with_appelation(appelation)
  if appelation
    @relation = @relation
      .where(:appelation.in => appelation)

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

#with_colors(colors) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 65

def with_colors(colors)
  if colors
    @relation = @relation
      .any_in('color' => colors)

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

#with_grapes(grapes) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 91

def with_grapes(grapes)
  if grapes
    @relation = @relation
      .any_in('vintages.grapes.key' => grapes)

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

#with_labelObject



56
57
58
59
60
61
62
63
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 56

def with_label
  @relation = @relation
    .where(:vintages.elem_match => { :wine_label.exists => true })

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

#with_storage_duration(durations) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 104

def with_storage_duration(durations)
  if durations
    @relation = @relation
      .any_in('vintages.storage_duration' => durations)

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

#with_tasting_opportunities(opportunities) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 117

def with_tasting_opportunities(opportunities)
  if opportunities
    @relation = @relation
      .any_in('vintages.tasting_opportunities' => opportunities)

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

#with_vintage_id(vintage_id) ⇒ Object



26
27
28
29
30
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 26

def with_vintage_id(vintage_id)
  @relation
    .where('vintages._id' => vintage_id)
    .first
end

#without_labelObject



38
39
40
41
42
43
44
45
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 38

def without_label
  @relation = @relation
    .where(:vintages.elem_match => { :wine_label.exists => false })

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

#without_vintagesObject



47
48
49
50
51
52
53
54
# File 'lib/winewoo_core/repositories/mongo/queries/wine_query.rb', line 47

def without_vintages
  @relation = @relation
    .where(:vintages.exists => false)

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