Module: Woods::Console::Tools::Tier2

Defined in:
lib/woods/console/tools/tier2.rb

Overview

Tier 2: Domain-aware tools for querying live Rails data.

These tools build on Tier 1 primitives to provide higher-level domain operations: model diagnostics, data snapshots, validation, settings management, policy checks, and decorator invocation.

Each method builds a bridge request hash from validated parameters. The bridge executes the operation against the Rails environment.

Class Method Summary collapse

Class Method Details

.console_check_eligibility(model:, id:, feature:) ⇒ Hash

Check feature eligibility for a record.

Parameters:

  • model (String)

    Model name

  • id (Integer)

    Record primary key

  • feature (String)

    Feature name to check

Returns:

  • (Hash)

    Bridge request



101
102
103
# File 'lib/woods/console/tools/tier2.rb', line 101

def console_check_eligibility(model:, id:, feature:)
  { tool: 'check_eligibility', params: { model: model, id: id, feature: feature } }
end

.console_check_policy(model:, id:, user_id:, action:) ⇒ Hash

Check authorization policy for a record and user.

Parameters:

  • model (String)

    Model name

  • id (Integer)

    Record primary key

  • user_id (Integer)

    User to check authorization for

  • action (String)

    Policy action (e.g., “update”, “destroy”)

Returns:

  • (Hash)

    Bridge request



80
81
82
83
# File 'lib/woods/console/tools/tier2.rb', line 80

def console_check_policy(model:, id:, user_id:, action:)
  { tool: 'check_policy',
    params: { model: model, id: id, user_id: user_id, action: action } }
end

.console_check_setting(key:, namespace: nil) ⇒ Hash

Check a configuration setting value.

Parameters:

  • key (String)

    Setting key

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

    Setting namespace

Returns:

  • (Hash)

    Bridge request



57
58
59
# File 'lib/woods/console/tools/tier2.rb', line 57

def console_check_setting(key:, namespace: nil)
  { tool: 'check_setting', params: { key: key, namespace: namespace }.compact }
end

.console_data_snapshot(model:, id:, associations: nil, depth: 1) ⇒ Hash

Snapshot a record with its associations for debugging.

Parameters:

  • model (String)

    Model name

  • id (Integer)

    Record primary key

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

    Association names to include

  • depth (Integer) (defaults to: 1)

    Association traversal depth (default: 1, max: 3)

Returns:

  • (Hash)

    Bridge request



36
37
38
39
40
# File 'lib/woods/console/tools/tier2.rb', line 36

def console_data_snapshot(model:, id:, associations: nil, depth: 1)
  depth = [depth, 3].min
  { tool: 'data_snapshot',
    params: { model: model, id: id, associations: associations, depth: depth }.compact }
end

.console_decorate(model:, id:, methods: nil) ⇒ Hash

Invoke a decorator on a record and return computed attributes.

Parameters:

  • model (String)

    Model name

  • id (Integer)

    Record primary key

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

    Specific decorator methods to call

Returns:

  • (Hash)

    Bridge request



111
112
113
# File 'lib/woods/console/tools/tier2.rb', line 111

def console_decorate(model:, id:, methods: nil)
  { tool: 'decorate', params: { model: model, id: id, methods: methods }.compact }
end

.console_diagnose_model(model:, scope: nil, sample_size: 5) ⇒ Hash

Diagnose a model by composing multiple queries: count, recent records, and aggregates.

Parameters:

  • model (String)

    Model name

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

    Filter conditions

  • sample_size (Integer) (defaults to: 5)

    Number of sample records (default: 5, max: 25)

Returns:

  • (Hash)

    Bridge request



24
25
26
27
# File 'lib/woods/console/tools/tier2.rb', line 24

def console_diagnose_model(model:, scope: nil, sample_size: 5)
  sample_size = [sample_size, 25].min
  { tool: 'diagnose_model', params: { model: model, scope: scope, sample_size: sample_size }.compact }
end

.console_update_setting(key:, value:, namespace: nil) ⇒ Hash

Update a configuration setting (requires human confirmation).

Parameters:

  • key (String)

    Setting key

  • value (Object)

    New value

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

    Setting namespace

Returns:

  • (Hash)

    Bridge request with requires_confirmation flag



67
68
69
70
71
# File 'lib/woods/console/tools/tier2.rb', line 67

def console_update_setting(key:, value:, namespace: nil)
  { tool: 'update_setting',
    params: { key: key, value: value, namespace: namespace }.compact,
    requires_confirmation: true }
end

.console_validate_record(model:, id:, attributes: nil) ⇒ Hash

Run validations on an existing record, optionally with changed attributes.

Parameters:

  • model (String)

    Model name

  • id (Integer)

    Record primary key

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

    Attributes to set before validating

Returns:

  • (Hash)

    Bridge request



48
49
50
# File 'lib/woods/console/tools/tier2.rb', line 48

def console_validate_record(model:, id:, attributes: nil)
  { tool: 'validate_record', params: { model: model, id: id, attributes: attributes }.compact }
end

.console_validate_with(model:, attributes:, context: nil) ⇒ Hash

Validate attributes against a model without persisting.

Parameters:

  • model (String)

    Model name

  • attributes (Hash)

    Attributes to validate

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

    Validation context (e.g., “create”, “update”)

Returns:

  • (Hash)

    Bridge request



91
92
93
# File 'lib/woods/console/tools/tier2.rb', line 91

def console_validate_with(model:, attributes:, context: nil)
  { tool: 'validate_with', params: { model: model, attributes: attributes, context: context }.compact }
end