Sha256: a040978027b1d67748ece7e5404939df44dedd499fc7961fc6ab31952f14a5ab

Contents?: true

Size: 1.62 KB

Versions: 13

Compression:

Stored size: 1.62 KB

Contents

module Jets::Command
  module RakeDecorate
    # Decorate this method because this does not get called until runtime.
    # It's "lazy loaded" so we can avoid the Rails const being defined in general.
    def [](task_name, scopes=nil)
      super # => Rake::TaskManager#[]
    rescue RuntimeError => e
      # We require dummy/rails since this time because all the rake tasks have been loaded
      # and we need to load dummy/rails to get the database configurations. Normally,
      # we do not want to require dummy/rails because it defines the Rails.
      # However, a "command not found" error, more accurately,
      # a "rake task not found" error, has already been encountered.
      # Also:
      # require "dummy/rails" to prevent another error.
      #   from lib/active_record/railties/databases.rake
      #
      #   NoMethodError: undefined method `env' for Rails:Module (NoMethodError)
      #     database_configs = ActiveRecord::DatabaseConfigurations.new(databases).configs_for(env_name: Rails.env)
      #
      require "jets/overrides/dummy/rails"

      # Original error message from rake is something like this
      #
      #   Don't know how to build task 'foo:bar' (See the list of available tasks with `jets --tasks`)
      #
      # With an ugly backtrace.
      # We override the error message to be more user friendly.
      #
      # All of that in order for
      #   jets foo:bar
      # to show a pretty error message.
      $stderr.puts "ERROR: Could not find command: #{task_name.inspect}".color(:red)
      require "jets/commands/help/help_command"
      Jets::Command::HelpCommand.new.help
      exit 1
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
jets-5.0.13 lib/jets/command/rake_decorate.rb
jets-5.0.12 lib/jets/command/rake_decorate.rb
jets-5.0.11 lib/jets/command/rake_decorate.rb
jets-5.0.10 lib/jets/command/rake_decorate.rb
jets-5.0.9 lib/jets/command/rake_decorate.rb
jets-5.0.8 lib/jets/command/rake_decorate.rb
jets-5.0.7 lib/jets/command/rake_decorate.rb
jets-5.0.6 lib/jets/command/rake_decorate.rb
jets-5.0.5 lib/jets/command/rake_decorate.rb
jets-5.0.4 lib/jets/command/rake_decorate.rb
jets-5.0.3 lib/jets/command/rake_decorate.rb
jets-5.0.2 lib/jets/command/rake_decorate.rb
jets-5.0.1 lib/jets/command/rake_decorate.rb