Module: Vanity::Autoconnect

Defined in:
lib/vanity/autoconnect.rb

Overview

A singleton responsible for determining if the playground should connect to the datastore.

Constant Summary

BLACKLISTED_RAILS_RAKE_TASKS =
[
  'about',
  'assets:clean',
  'assets:clobber',
  'assets:environment',
  'assets:precompile',
  'assets:precompile:all',
  'db:create',
  'db:drop',
  'db:fixtures:load',
  'db:migrate',
  'db:migrate:status',
  'db:rollback',
  'db:reset',
  'db:schema:cache:clear',
  'db:schema:cache:dump',
  'db:schema:dump',
  'db:schema:load',
  'db:seed',
  'db:setup',
  'db:structure:dump',
  'db:test:load',
  'db:version',
  'doc:app',
  'log:clear',
  'middleware',
  'notes',
  'notes:custom',
  'rails:template',
  'rails:update',
  'routes',
  'secret',
  'stats',
  'time:zones:all',
  'tmp:clear',
  'tmp:create'
]
ENVIRONMENT_VANITY_DISABLED_FLAG =
"VANITY_DISABLED"

Class Method Summary collapse

Class Method Details

.current_rake_tasksObject



63
64
65
66
67
# File 'lib/vanity/autoconnect.rb', line 63

def current_rake_tasks
  ::Rake.application.top_level_tasks
rescue
  []
end

.environment_disabled?Boolean



55
56
57
# File 'lib/vanity/autoconnect.rb', line 55

def environment_disabled?
  !!ENV[ENVIRONMENT_VANITY_DISABLED_FLAG]
end

.in_blacklisted_rake_task?Boolean



59
60
61
# File 'lib/vanity/autoconnect.rb', line 59

def in_blacklisted_rake_task?
  !(current_rake_tasks & BLACKLISTED_RAILS_RAKE_TASKS).empty?
end

.schema_relevant?Boolean



51
52
53
# File 'lib/vanity/autoconnect.rb', line 51

def schema_relevant?
  current_rake_tasks.any? { |task| task =~ /\Adb:/ }
end

.should_connect?Boolean Also known as: playground_should_autoconnect?



46
47
48
# File 'lib/vanity/autoconnect.rb', line 46

def should_connect?
  !environment_disabled? && !in_blacklisted_rake_task?
end