Class: RailsConsolePro::Commands::QueryBuilderCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/rails_console_pro/commands/query_builder_command.rb

Overview

Command for interactive query building

Instance Method Summary collapse

Methods included from RailsConsolePro::ColorHelper

#bold_color, #color, #method_missing, #pastel, #respond_to_missing?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class RailsConsolePro::ColorHelper

Instance Method Details

#execute(model_class, &block) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rails_console_pro/commands/query_builder_command.rb', line 7

def execute(model_class, &block)
  return disabled_message unless enabled?
  return pastel.red("#{model_class} is not an ActiveRecord model") unless valid_model?(model_class)

  builder = QueryBuilder.new(model_class)
  
  if block_given?
    builder.instance_eval(&block)
    builder.build
  else
    builder.build
  end
rescue => e
  RailsConsolePro::ErrorHandler.handle(e, context: :query_builder)
end