Class: PGB::Model
- Inherits:
-
Object
- Object
- PGB::Model
- Extended by:
- Enumerable, Shortcuts
- Includes:
- Shortcuts
- Defined in:
- lib/pgb/model.rb
Overview
TODO Explicit table names TODO Support queries for from TODO Automatically infer validations from db constraints TODO Do not litter this class with methods since others inherit from it (e.g. parse) TODO Support explicitly setting table_name / query / etc TODO table_name changing at runtime TODO Defined attributes might be needed before connecting to the database TODO Support keyword attributes for #new and make parse use that TODO #inspect TODO #to_s TODO Module inclusions on relations? TODO Include enumerable methods unless they clash with existing TODO Enumerable methods should act on current selection TODO Check all enumerable methods are functional (e.g. sort, to_h) TODO Implement base methods, e.g. ==, etc TODO Check Enumerable and Shortcuts methods clashing (e.g. []) TODO Lazy for enumerable
Direct Known Subclasses
Class Attribute Summary collapse
-
.table_name ⇒ Object
readonly
Returns the value of attribute table_name.
Class Method Summary collapse
-
.all ⇒ Object
TODO Only execute when data is required TODO Schema auto reload? TODO Schema manual reload? TODO Called again? Remove all conditions or do nothing?.
- .columns ⇒ Object
- .each ⇒ Object
- .inherited(klass) ⇒ Object
-
.schema ⇒ Object
TODO Column names clashing with existing methods TODO Overwriting column readers / writers.
Methods included from Shortcuts
[], execute, from, func, lit, select
Class Attribute Details
.table_name ⇒ Object
Returns the value of attribute table_name.
29 30 31 |
# File 'lib/pgb/model.rb', line 29 def table_name @table_name end |
Class Method Details
.all ⇒ Object
TODO Only execute when data is required TODO Schema auto reload? TODO Schema manual reload? TODO Called again? Remove all conditions or do nothing?
44 45 46 |
# File 'lib/pgb/model.rb', line 44 def all from(table_name).then { execute(_1) }.map { parse(_1) } end |
.columns ⇒ Object
58 59 60 |
# File 'lib/pgb/model.rb', line 58 def columns schema.keys end |
.each ⇒ Object
36 37 38 |
# File 'lib/pgb/model.rb', line 36 def each all.each { yield _1 } end |
.inherited(klass) ⇒ Object
31 32 33 34 |
# File 'lib/pgb/model.rb', line 31 def inherited(klass) # TODO Bad method for setting table name klass.table_name = "#{klass.name.downcase.split('::').last}s" end |