Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Supporting class for demo purposes
- class DatabaseStub
- attr_reader :name
- def self.instances
- ["development", "test", "ci"]
- end
- def initialize(databaseName)
- @name = databaseName
- end
- def running?
- @name == "development"
- end
- def method_missing(sym, *args, &block)
- puts "Action '#{sym}' would now be performed on database '#@name'"
- end
- end
- # Define our own task type
- def task_database(database, action)
- desc "#{action.to_s} - #{database.name}"
- task action do
- # Use message sending to just pass on the action to the
- # instance.
- database.send(action)
- end
- end
- # Define the tasks
- DatabaseStub.instances.each do |databaseName|
- namespace databaseName do
- database = DatabaseStub.new(databaseName)
- task_database(database, :status)
- task_database(database, :restart)
- if database.running?
- task_database(database, :stop)
- else
- task_database(database, :start)
- end
- end
- end
Add Comment
Please, Sign In to add comment