Module: BaseExtension
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/record_neighbors/base_extension.rb
Instance Method Summary collapse
- #all_after(attribute = "id") ⇒ Object
- #all_before(attribute = "id") ⇒ Object
- #all_without ⇒ Object
- #first?(attribute = "id") ⇒ Boolean
- #last?(attribute = "id") ⇒ Boolean
- #next(attribute = "id") ⇒ Object
- #previous(attribute = "id") ⇒ Object
Instance Method Details
#all_after(attribute = "id") ⇒ Object
22 23 24 |
# File 'lib/record_neighbors/base_extension.rb', line 22 def all_after(attribute = "id") self.class.where("#{attribute} > #{self.send(attribute)}").order("#{attribute} ASC") end |
#all_before(attribute = "id") ⇒ Object
26 27 28 |
# File 'lib/record_neighbors/base_extension.rb', line 26 def all_before(attribute = "id") self.class.where("#{attribute} < #{self.send(attribute)}").order("#{attribute} ASC") end |
#all_without ⇒ Object
30 31 32 |
# File 'lib/record_neighbors/base_extension.rb', line 30 def all_without self.class.where.not(id: self.id) end |
#first?(attribute = "id") ⇒ Boolean
10 11 12 |
# File 'lib/record_neighbors/base_extension.rb', line 10 def first?(attribute = "id") self == self.class.order("#{attribute} ASC").first end |
#last?(attribute = "id") ⇒ Boolean
6 7 8 |
# File 'lib/record_neighbors/base_extension.rb', line 6 def last?(attribute = "id") self == self.class.order("#{attribute} ASC").last end |
#next(attribute = "id") ⇒ Object
14 15 16 |
# File 'lib/record_neighbors/base_extension.rb', line 14 def next(attribute = "id") self.class.where("#{attribute} > #{self.send(attribute)}").order("#{attribute} ASC").limit(1).first end |
#previous(attribute = "id") ⇒ Object
18 19 20 |
# File 'lib/record_neighbors/base_extension.rb', line 18 def previous(attribute = "id") self.class.where("#{attribute} < #{self.send(attribute)}").order("#{attribute} DESC").limit(1).first end |