Class: Alchemy::Upgrader
- Inherits:
-
Object
- Object
- Alchemy::Upgrader
- Includes:
- Shell, Thor::Actions, Thor::Base
- Defined in:
- lib/alchemy/upgrader.rb,
lib/alchemy/upgrader/eight_one.rb,
lib/alchemy/upgrader/eight_zero.rb
Defined Under Namespace
Constant Summary collapse
- VERSION_MODULE_MAP =
{ "8.0" => "Alchemy::Upgrader::EightZero", "8.1" => "Alchemy::Upgrader::EightOne" }
Constants included from Shell
Class Method Summary collapse
-
.[](version) ⇒ Object
Returns a memoized upgrader instance for the given version.
Instance Method Summary collapse
-
#initialize(version) ⇒ Upgrader
constructor
A new instance of Upgrader.
- #run_migrations ⇒ Object
- #update_config ⇒ Object
Methods included from Shell
#add_todo, #desc, #display_todos, #log, silence!, silenced?, #todo, #todos, verbose!
Constructor Details
#initialize(version) ⇒ Upgrader
Returns a new instance of Upgrader.
28 29 30 31 |
# File 'lib/alchemy/upgrader.rb', line 28 def initialize(version) super() self.class.include VERSION_MODULE_MAP[version.to_s].constantize end |
Class Method Details
.[](version) ⇒ Object
Returns a memoized upgrader instance for the given version. This ensures todos are accumulated across rake tasks.
23 24 25 26 |
# File 'lib/alchemy/upgrader.rb', line 23 def self.[](version) @instances ||= {} @instances[version.to_s] ||= new(version) end |
Instance Method Details
#run_migrations ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/alchemy/upgrader.rb', line 39 def run_migrations ActiveRecord::Migration.check_all_pending! rescue ActiveRecord::PendingMigrationError desc "Pending Database migrations." if yes?("Run database migrations now? (y/N)") log "Migrating Database..." Rake::Task["db:migrate"].invoke else log "Don't forget to run database migrations later with rake `db:migrate`.", :skip end end |
#update_config ⇒ Object
33 34 35 36 37 |
# File 'lib/alchemy/upgrader.rb', line 33 def update_config desc "Copy configuration file." @default_config = Alchemy::Configurations::Main.new template("templates/alchemy.rb.tt", "config/initializers/alchemy.rb") end |