class Vindi::Model

Base model to vindi resources.

Public Class Methods

first(limit = 1) click to toggle source

@example First Customer

@customer = Vindi::Customer.first

@example First two customers

@customers = Vindi::Customer.first(2)
# File lib/vindi/models/model.rb, line 54
def first(limit = 1)
  records = order_by(:created_at, :asc).per_page(limit)

  return records[0] if limit == 1

  records
end
last(limit = 1) click to toggle source

@example Last customer

@customer = Vindi::Customer.last

@example Last two customers

@customers = Vindi::Customer.last(2)
# File lib/vindi/models/model.rb, line 68
def last(limit = 1)
  records = order_by(:created_at, :desc).per_page(limit)

  return records[0] if limit == 1

  records
end

Public Instance Methods

archive!() click to toggle source

Archive a record.

@example Archive a customer

Vindi::Customer.find_by(email: "sarumanthewhite@middlearth.io").archive!
# File lib/vindi/models/model.rb, line 38
def archive!
  destroy
end
valid?() click to toggle source

@private

Calls superclass method
# File lib/vindi/models/model.rb, line 43
def valid?
  super && response_errors.empty?
end