Class: Pokeedex::Pokemon::Model::Base
- Inherits:
-
Object
- Object
- Pokeedex::Pokemon::Model::Base
- Defined in:
- lib/pokeedex/pokemon/model/base.rb
Overview
Base class for the Pokemon model. It holds the database connection and the methods to interact with the database table for the Pokemon model
Constant Summary collapse
- CACHE_TTL =
3600
Class Method Summary collapse
-
.search(query) ⇒ Object
Search for a Pokemon by number or name.
Instance Method Summary collapse
-
#persisted? ⇒ Boolean
Return true when the Pokemon model is persisted in the database.
-
#validate ⇒ Object
Validate the Pokemon model attributes.
Class Method Details
.search(query) ⇒ Object
Search for a Pokemon by number or name
23 24 25 |
# File 'lib/pokeedex/pokemon/model/base.rb', line 23 def self.search(query) where(Sequel.|({ number: query }, Sequel.ilike(:name, query))) end |
Instance Method Details
#persisted? ⇒ Boolean
Return true when the Pokemon model is persisted in the database
37 38 39 |
# File 'lib/pokeedex/pokemon/model/base.rb', line 37 def persisted? !id.nil? end |
#validate ⇒ Object
Validate the Pokemon model attributes
29 30 31 32 33 |
# File 'lib/pokeedex/pokemon/model/base.rb', line 29 def validate super validates_presence %i[number name] validates_unique :number end |