Module: Mongoid::Report::ClassMethods
- Defined in:
- lib/mongoid/report.rb
Instance Method Summary collapse
- #attach_to(*fields, &block) ⇒ Object
- #batches(*fields) ⇒ Object
- #column(*fields) ⇒ Object
- #columns(*fields) ⇒ Object
- #get_settings(report_module, report_name, field) ⇒ Object
- #group_by(*fields) ⇒ Object
- #mapping(*fields) ⇒ Object
- #match(*fields) ⇒ Object
- #query(*fields) ⇒ Object
- #report(name, &block) ⇒ Object
- #set_settings(report_module, report_name, field, value) ⇒ Object
Instance Method Details
#attach_to(*fields, &block) ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/mongoid/report.rb', line 149 def attach_to(*fields, &block) = fields. collection = fields[0] .merge!(report_name: [:as]) if [:as] define_report_method(.merge(collection: collection)) do proxy = AttachProxy.new(self, collection, ) proxy.instance_eval(&block) end end |
#batches(*fields) ⇒ Object
161 162 163 164 165 |
# File 'lib/mongoid/report.rb', line 161 def batches(*fields) define_report_method(*fields) do |_, report_module, report_name, batches| self.set_settings(report_module, report_name, :batches, batches.stringify_keys!) end end |
#column(*fields) ⇒ Object
196 197 198 199 200 201 202 |
# File 'lib/mongoid/report.rb', line 196 def column(*fields) define_report_method(*fields) do |columns, report_module, report_name, _| columns.each do |field| self.get_settings(report_module, report_name, :fields) << field.to_s end end end |
#columns(*fields) ⇒ Object
204 205 206 207 208 |
# File 'lib/mongoid/report.rb', line 204 def columns(*fields) define_report_method(*fields) do |_, report_module, report_name, columns| self.set_settings(report_module, report_name, :columns, columns.stringify_keys!) end end |
#get_settings(report_module, report_name, field) ⇒ Object
222 223 224 225 226 227 228 |
# File 'lib/mongoid/report.rb', line 222 def get_settings(report_module, report_name, field) unless report_name self.settings[report_module][field] else self.settings[report_module][:reports][report_name][field] end end |
#group_by(*fields) ⇒ Object
190 191 192 193 194 |
# File 'lib/mongoid/report.rb', line 190 def group_by(*fields) define_report_method(*fields) do |groups, report_module, report_name, _| self.set_settings(report_module, report_name, :group_by, groups.map(&:to_s)) end end |
#mapping(*fields) ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/mongoid/report.rb', line 210 def mapping(*fields) define_report_method(*fields) do |_, report_module, report_name, mapping| mapping.stringify_keys! mapping.each do |key, value| mapping[key] = value.to_s end self.set_settings(report_module, report_name, :mapping, mapping) end end |
#match(*fields) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/mongoid/report.rb', line 167 def match(*fields) define_report_method(*fields) do |_, report_module, report_name, | queries = self.get_settings(report_module, report_name, :queries) .each do |key, value| queries .concat([{ '$match' => { key => value } }]) end end end |
#query(*fields) ⇒ Object
180 181 182 183 184 185 186 187 188 |
# File 'lib/mongoid/report.rb', line 180 def query(*fields) define_report_method(*fields) do |_, report_module, report_name, | queries = self.get_settings(report_module, report_name, :queries) .each do |key, value| queries.concat([{ key => value }]) end end end |
#report(name, &block) ⇒ Object
144 145 146 147 |
# File 'lib/mongoid/report.rb', line 144 def report(name, &block) proxy = ReportProxy.new(self, name) proxy.instance_eval(&block) end |
#set_settings(report_module, report_name, field, value) ⇒ Object
230 231 232 233 234 235 236 |
# File 'lib/mongoid/report.rb', line 230 def set_settings(report_module, report_name, field, value) unless report_name self.settings[report_module][field] = value else self.settings[report_module][:reports][report_name][field] = value end end |