Class: Vindi::Model

Inherits:
Object
  • Object
show all
Includes:
Her::Model
Defined in:
lib/vindi/models/model.rb

Overview

Base model to vindi resources.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.first(limit = 1) ⇒ Object

Examples:

First Customer

@customer = Vindi::Customer.first

First two customers

@customers = Vindi::Customer.first(2)


56
57
58
59
60
61
62
# File 'lib/vindi/models/model.rb', line 56

def first(limit = 1)
  records = order_by(:created_at, :asc).per_page(limit)

  return records[0] if limit == 1

  records
end

.last(limit = 1) ⇒ Object

Examples:

Last customer

@customer = Vindi::Customer.last

Last two customers

@customers = Vindi::Customer.last(2)


70
71
72
73
74
75
76
# File 'lib/vindi/models/model.rb', line 70

def last(limit = 1)
  records = order_by(:created_at, :desc).per_page(limit)

  return records[0] if limit == 1

  records
end

Instance Method Details

#archive!Object

Archive a record.

Examples:

Archive a customer


Vindi::Customer.find_by(email: "[email protected]").archive!


40
41
42
# File 'lib/vindi/models/model.rb', line 40

def archive!
  destroy
end

#valid?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/vindi/models/model.rb', line 45

def valid?
  super && response_errors.empty?
end