Guest User

Untitled

a guest
Feb 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. # Supporting class for demo purposes
  2. class DatabaseStub
  3. attr_reader :name
  4.  
  5. def self.instances
  6. ["development", "test", "ci"]
  7. end
  8.  
  9. def initialize(databaseName)
  10. @name = databaseName
  11. end
  12.  
  13. def running?
  14. @name == "development"
  15. end
  16.  
  17. def method_missing(sym, *args, &block)
  18. puts "Action '#{sym}' would now be performed on database '#@name'"
  19. end
  20. end
  21.  
  22. # Define our own task type
  23. def task_database(database, action)
  24. desc "#{action.to_s} - #{database.name}"
  25. task action do
  26. # Use message sending to just pass on the action to the
  27. # instance.
  28. database.send(action)
  29. end
  30. end
  31.  
  32. # Define the tasks
  33. DatabaseStub.instances.each do |databaseName|
  34. namespace databaseName do
  35. database = DatabaseStub.new(databaseName)
  36.  
  37. task_database(database, :status)
  38. task_database(database, :restart)
  39.  
  40. if database.running?
  41. task_database(database, :stop)
  42. else
  43. task_database(database, :start)
  44. end
  45.  
  46. end
  47. end
Add Comment
Please, Sign In to add comment