Module: Mongoid::Timeline::Record::ClassMethods
- Defined in:
- lib/obscured-timeline/record.rb
Instance Method Summary collapse
Instance Method Details
#by(params = {}, options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/obscured-timeline/record.rb', line 52 def by(params = {}, = {}) limit = [:limit].blank? ? nil : [:limit].to_i skip = [:skip].blank? ? nil : [:skip].to_i order = [:order].blank? ? :created_at.desc : [:order] only = [:only].blank? ? %i[id type message producer created_at updated_at proprietor] : [:only] query = {} query[:type] = params[:type].to_sym if params[:type] query[:severity] = params[:severity].to_sym if params[:severity] query[:producer] = params[:producer].to_sym if params[:producer] params[:proprietor]&.map { |k, v| query.merge!("proprietor.#{k}" => v) } criterion = where(query).only(only).limit(limit).skip(skip) criterion = criterion.order_by(order) if order docs = criterion.to_a docs end |
#make(params = {}) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/obscured-timeline/record.rb', line 30 def make(params = {}) raise ArgumentError, 'type missing' if params[:type].blank? raise ArgumentError, 'type must be a symbol' unless params[:type].instance_of?(Symbol) raise ArgumentError, 'message missing' if params[:message].nil? raise ArgumentError, 'producer missing' if params[:producer].blank? raise ArgumentError, 'proprietor missing' if params[:proprietor].blank? doc = new doc.type = params[:type] doc.severity = params[:severity].to_sym unless params[:severity].blank? doc. = params[:message] doc.producer = params[:producer] doc.proprietor = params[:proprietor] doc end |
#make!(params = {}) ⇒ Object
46 47 48 49 50 |
# File 'lib/obscured-timeline/record.rb', line 46 def make!(params = {}) doc = make(params) doc.save! doc end |