Module: Woods::Console::Tools::Tier1
- Defined in:
- lib/woods/console/tools/tier1.rb
Overview
Tier 1: MVP read-only tools for querying live Rails data.
Each method builds a bridge request hash from validated parameters. The bridge executes the query against the Rails database.
Class Method Summary collapse
-
.console_aggregate(model:, function:, column: nil, scope: nil) ⇒ Hash
Run aggregate function on a column.
-
.console_association_count(model:, id:, association:, scope: nil) ⇒ Hash
Count associated records.
-
.console_count(model:, scope: nil) ⇒ Hash
Count records matching scope conditions.
-
.console_find(model:, id: nil, by: nil, columns: nil) ⇒ Hash
Find a single record by primary key or unique column.
-
.console_pluck(model:, columns:, scope: nil, limit: 100, distinct: false) ⇒ Hash
Extract column values.
-
.console_recent(model:, order_by: 'created_at', direction: 'desc', limit: 10, scope: nil, columns: nil) ⇒ Hash
Recently created/updated records.
-
.console_sample(model:, scope: nil, limit: 5, columns: nil) ⇒ Hash
Random sample of records.
-
.console_schema(model:, include_indexes: false) ⇒ Hash
Get database schema for a model.
-
.console_status ⇒ Hash
System health check.
Class Method Details
.console_aggregate(model:, function:, column: nil, scope: nil) ⇒ Hash
Run aggregate function on a column.
67 68 69 |
# File 'lib/woods/console/tools/tier1.rb', line 67 def console_aggregate(model:, function:, column: nil, scope: nil) { tool: 'aggregate', params: { model: model, function: function, column: column, scope: scope }.compact } end |
.console_association_count(model:, id:, association:, scope: nil) ⇒ Hash
Count associated records.
78 79 80 81 |
# File 'lib/woods/console/tools/tier1.rb', line 78 def console_association_count(model:, id:, association:, scope: nil) { tool: 'association_count', params: { model: model, id: id, association: association, scope: scope }.compact } end |
.console_count(model:, scope: nil) ⇒ Hash
Count records matching scope conditions.
19 20 21 |
# File 'lib/woods/console/tools/tier1.rb', line 19 def console_count(model:, scope: nil) { tool: 'count', params: { model: model, scope: scope }.compact } end |
.console_find(model:, id: nil, by: nil, columns: nil) ⇒ Hash
Find a single record by primary key or unique column.
42 43 44 |
# File 'lib/woods/console/tools/tier1.rb', line 42 def console_find(model:, id: nil, by: nil, columns: nil) { tool: 'find', params: { model: model, id: id, by: by, columns: columns }.compact } end |
.console_pluck(model:, columns:, scope: nil, limit: 100, distinct: false) ⇒ Hash
Extract column values.
54 55 56 57 58 |
# File 'lib/woods/console/tools/tier1.rb', line 54 def console_pluck(model:, columns:, scope: nil, limit: 100, distinct: false) limit = [limit, 1000].min { tool: 'pluck', params: { model: model, columns: columns, scope: scope, limit: limit, distinct: distinct }.compact } end |
.console_recent(model:, order_by: 'created_at', direction: 'desc', limit: 10, scope: nil, columns: nil) ⇒ Hash
Recently created/updated records.
rubocop:disable Metrics/ParameterLists
102 103 104 105 106 |
# File 'lib/woods/console/tools/tier1.rb', line 102 def console_recent(model:, order_by: 'created_at', direction: 'desc', limit: 10, scope: nil, columns: nil) limit = [limit, 50].min { tool: 'recent', params: { model: model, order_by: order_by, direction: direction, limit: limit, scope: scope, columns: columns }.compact } end |
.console_sample(model:, scope: nil, limit: 5, columns: nil) ⇒ Hash
Random sample of records.
30 31 32 33 |
# File 'lib/woods/console/tools/tier1.rb', line 30 def console_sample(model:, scope: nil, limit: 5, columns: nil) limit = [limit, 25].min { tool: 'sample', params: { model: model, scope: scope, limit: limit, columns: columns }.compact } end |
.console_schema(model:, include_indexes: false) ⇒ Hash
Get database schema for a model.
88 89 90 |
# File 'lib/woods/console/tools/tier1.rb', line 88 def console_schema(model:, include_indexes: false) { tool: 'schema', params: { model: model, include_indexes: include_indexes } } end |
.console_status ⇒ Hash
System health check.
112 113 114 |
# File 'lib/woods/console/tools/tier1.rb', line 112 def console_status { tool: 'status', params: {} } end |