Class: Veksel::Commands::List
- Inherits:
-
Object
- Object
- Veksel::Commands::List
- Defined in:
- lib/veksel/commands/list.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
Instance Method Summary collapse
-
#initialize(db) ⇒ List
constructor
A new instance of List.
- #perform ⇒ Object
Constructor Details
#initialize(db) ⇒ List
Returns a new instance of List.
6 7 8 |
# File 'lib/veksel/commands/list.rb', line 6 def initialize(db) @adapter = Veksel.adapter_for(db.configuration_hash) end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
4 5 6 |
# File 'lib/veksel/commands/list.rb', line 4 def adapter @adapter end |
Instance Method Details
#perform ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/veksel/commands/list.rb', line 10 def perform databases = adapter.forked_databases active_branches = Veksel.active_branches if databases.empty? puts "No databases created by Veksel" return end hash = {} databases.each do |database| branch = database.branch hash[branch] = database.name end longest_branch_name = hash.keys.max_by(&:length).length longest_database_name = hash.values.max_by(&:length).length puts "Databases created by Veksel:" puts "" puts "#{'Branch'.ljust(longest_branch_name)} #{'Database'.ljust(longest_database_name)} Active" inactive_count = 0 hash.each do |branch, database| # Print a formatted string padded to fit the longest branch name active = active_branches.include?(branch) ? 'Yes' : 'No' inactive_count += 1 if active == 'No' puts "#{branch.ljust(longest_branch_name)} #{database.ljust(longest_database_name)} #{active}" end if inactive_count > 0 puts "" puts "Clean inactive databases with bin/rails veksel:clean" end end |