Class: Themigrator::Migration
- Inherits:
-
Object
- Object
- Themigrator::Migration
- Defined in:
- lib/themigrator/migration.rb
Overview
Holds the plan of the migration
Constant Summary collapse
- ACTIONS =
%w(setup pre-migrate migrate cleanup)
- SCRIPTS =
ACTIONS | %w(rollback)
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#roles ⇒ Object
readonly
Returns the value of attribute roles.
Instance Method Summary collapse
- #analyze_project! ⇒ Object
-
#initialize(dir) ⇒ Migration
constructor
A new instance of Migration.
- #roles_for_action(action) ⇒ Object
Constructor Details
#initialize(dir) ⇒ Migration
Returns a new instance of Migration.
13 14 15 16 17 18 |
# File 'lib/themigrator/migration.rb', line 13 def initialize(dir) @dir = dir @action_and_roles = Hash.new{|hash,key| hash[key] = [] } @roles = [] @actions = [] end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
11 12 13 |
# File 'lib/themigrator/migration.rb', line 11 def actions @actions end |
#roles ⇒ Object (readonly)
Returns the value of attribute roles.
11 12 13 |
# File 'lib/themigrator/migration.rb', line 11 def roles @roles end |
Instance Method Details
#analyze_project! ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/themigrator/migration.rb', line 20 def analyze_project! roles = Set.new used_actions = [] # Should be in order SCRIPTS.each do |action| path_match = File.join(@dir,"*/#{action}") Dir[path_match].select { |f| File.executable?(f) }.each {|f| role = File.basename(File.dirname(f)) roles.add(role) used_actions << action @action_and_roles[action] << role } end @roles = roles.to_a.sort @actions = used_actions.uniq @actions.delete("rollback") end |
#roles_for_action(action) ⇒ Object
42 43 44 |
# File 'lib/themigrator/migration.rb', line 42 def roles_for_action(action) @action_and_roles[action] end |