Module: Obscured::Heartbeat::Record::ClassMethods
- Defined in:
- lib/obscured-heartbeat/record.rb
Instance Method Summary collapse
Instance Method Details
#by(params = {}, options = {}) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/obscured-heartbeat/record.rb', line 51 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 distrubuton hostname ip_address uptime created_at updated_at proprietor] : [:only] query = {} query[:hostname] = params[:hostname] if params[:hostname] 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
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/obscured-heartbeat/record.rb', line 29 def make(params = {}) raise ArgumentError, 'distribution missing' if params[:distribution].blank? raise ArgumentError, 'hostname missing' if params[:hostname].blank? raise ArgumentError, 'ip_address missing' if params[:ip_address].blank? raise ArgumentError, 'uptime missing' if params[:uptime].blank? raise ArgumentError, 'proprietor missing' if params[:proprietor].blank? doc = new doc.distribution = params[:distribution] doc.hostname = params[:hostname] doc.ip_address = params[:ip_address] doc.uptime = params[:uptime] doc.proprietor = params[:proprietor] doc end |
#make!(params = {}) ⇒ Object
45 46 47 48 49 |
# File 'lib/obscured-heartbeat/record.rb', line 45 def make!(params = {}) doc = make(params) doc.save! doc end |