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

Class Method Details

.console_aggregate(model:, function:, column: nil, scope: nil) ⇒ Hash

Run aggregate function on a column.

Parameters:

  • model (String)

    Model name

  • function (String)

    One of: sum, average, minimum, maximum, count

  • column (String, nil) (defaults to: nil)

    Column to aggregate (optional for count)

  • scope (Hash, nil) (defaults to: nil)

    Filter conditions

Returns:

  • (Hash)

    Bridge request



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.

Parameters:

  • model (String)

    Model name

  • id (Integer)

    Record primary key

  • association (String)

    Association name

  • scope (Hash, nil) (defaults to: nil)

    Filter on the association

Returns:

  • (Hash)

    Bridge request



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.

Parameters:

  • model (String)

    Model name

  • scope (Hash, nil) (defaults to: nil)

    Filter conditions

Returns:

  • (Hash)

    Bridge request



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.

Parameters:

  • model (String)

    Model name

  • id (Integer, nil) (defaults to: nil)

    Primary key value

  • by (Hash, nil) (defaults to: nil)

    Unique column lookup (e.g., { email: “x@y.com” })

  • columns (Array<String>, nil) (defaults to: nil)

    Columns to include

Returns:

  • (Hash)

    Bridge request



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.

Parameters:

  • model (String)

    Model name

  • columns (Array<String>)

    Column names to pluck

  • scope (Hash, nil) (defaults to: nil)

    Filter conditions

  • limit (Integer) (defaults to: 100)

    Max records (default: 100, max: 1000)

  • distinct (Boolean) (defaults to: false)

    Return unique values only

Returns:

  • (Hash)

    Bridge request



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

Parameters:

  • model (String)

    Model name

  • order_by (String) (defaults to: 'created_at')

    Column to sort by (default: created_at)

  • direction (String) (defaults to: 'desc')

    Sort direction (default: desc)

  • limit (Integer) (defaults to: 10)

    Max records (default: 10, max: 50)

  • scope (Hash, nil) (defaults to: nil)

    Filter conditions

  • columns (Array<String>, nil) (defaults to: nil)

    Columns to include

Returns:

  • (Hash)

    Bridge request



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.

Parameters:

  • model (String)

    Model name

  • scope (Hash, nil) (defaults to: nil)

    Filter conditions

  • limit (Integer) (defaults to: 5)

    Max records (default: 5, max: 25)

  • columns (Array<String>, nil) (defaults to: nil)

    Columns to include

Returns:

  • (Hash)

    Bridge request



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.

Parameters:

  • model (String)

    Model name

  • include_indexes (Boolean) (defaults to: false)

    Include index information

Returns:

  • (Hash)

    Bridge request



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_statusHash

System health check.

Returns:

  • (Hash)

    Bridge request



112
113
114
# File 'lib/woods/console/tools/tier1.rb', line 112

def console_status
  { tool: 'status', params: {} }
end