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 collapse
- 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
- .current_rake_tasks ⇒ Object
- .environment_disabled? ⇒ Boolean
- .in_blacklisted_rake_task? ⇒ Boolean
- .schema_relevant? ⇒ Boolean
- .should_connect? ⇒ Boolean (also: playground_should_autoconnect?)
Class Method Details
.current_rake_tasks ⇒ Object
62 63 64 65 66 |
# File 'lib/vanity/autoconnect.rb', line 62 def current_rake_tasks ::Rake.application.top_level_tasks rescue StandardError [] end |
.environment_disabled? ⇒ Boolean
54 55 56 |
# File 'lib/vanity/autoconnect.rb', line 54 def environment_disabled? !!ENV[ENVIRONMENT_VANITY_DISABLED_FLAG] end |
.in_blacklisted_rake_task? ⇒ Boolean
58 59 60 |
# File 'lib/vanity/autoconnect.rb', line 58 def in_blacklisted_rake_task? !(current_rake_tasks & BLACKLISTED_RAILS_RAKE_TASKS).empty? end |
.schema_relevant? ⇒ Boolean
50 51 52 |
# File 'lib/vanity/autoconnect.rb', line 50 def schema_relevant? current_rake_tasks.any? { |task| task.start_with?('db:') } end |
.should_connect? ⇒ Boolean Also known as: playground_should_autoconnect?
45 46 47 |
# File 'lib/vanity/autoconnect.rb', line 45 def should_connect? !environment_disabled? && !in_blacklisted_rake_task? end |