Class: MigrExt::Migration
- Inherits:
-
Object
- Object
- MigrExt::Migration
- Defined in:
- lib/migrext/migration.rb
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#original_name ⇒ Object
readonly
Returns the value of attribute original_name.
-
#original_plugin ⇒ Object
readonly
Returns the value of attribute original_plugin.
-
#original_version ⇒ Object
readonly
Returns the value of attribute original_version.
-
#plugin ⇒ Object
readonly
Returns the value of attribute plugin.
-
#set ⇒ Object
readonly
Returns the value of attribute set.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #==(other_migration) ⇒ Object
- #create_rooted_content! ⇒ Object
- #imported? ⇒ Boolean
-
#initialize(set, filename) ⇒ Migration
constructor
A new instance of Migration.
- #inspect ⇒ Object
Constructor Details
#initialize(set, filename) ⇒ Migration
Returns a new instance of Migration.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/migrext/migration.rb', line 8 def initialize(set, filename) @set = set @filename = filename if filename =~ /(\d+)_(\w+)\.rb$/i @original_version = @version = $1.to_i @original_name = @name = $2 @original_plugin = @plugin = @set.name end if File.read(filename) =~ /#\s+imported\s+migration\s+(\d+)\s+(\w+)\s+from\s+(\w+)/i @version = $1.to_i @name = $2 @plugin = $3 end end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
3 4 5 |
# File 'lib/migrext/migration.rb', line 3 def filename @filename end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/migrext/migration.rb', line 5 def name @name end |
#original_name ⇒ Object (readonly)
Returns the value of attribute original_name.
6 7 8 |
# File 'lib/migrext/migration.rb', line 6 def original_name @original_name end |
#original_plugin ⇒ Object (readonly)
Returns the value of attribute original_plugin.
6 7 8 |
# File 'lib/migrext/migration.rb', line 6 def original_plugin @original_plugin end |
#original_version ⇒ Object (readonly)
Returns the value of attribute original_version.
6 7 8 |
# File 'lib/migrext/migration.rb', line 6 def original_version @original_version end |
#plugin ⇒ Object (readonly)
Returns the value of attribute plugin.
5 6 7 |
# File 'lib/migrext/migration.rb', line 5 def plugin @plugin end |
#set ⇒ Object (readonly)
Returns the value of attribute set.
3 4 5 |
# File 'lib/migrext/migration.rb', line 3 def set @set end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
5 6 7 |
# File 'lib/migrext/migration.rb', line 5 def version @version end |
Instance Method Details
#==(other_migration) ⇒ Object
25 26 27 |
# File 'lib/migrext/migration.rb', line 25 def ==(other_migration) version == other_migration.version && name == other_migration.name && plugin == other_migration.plugin end |
#create_rooted_content! ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/migrext/migration.rb', line 33 def create_rooted_content! if set.root? raise RuntimeError, "Set has to be from an extension root" end content = File.read(filename) name = set.name + "_" + self.name content.gsub! /^class \w+/, "class #{name.camelize}" content << "\n\n# imported migration #@version #@name from #@plugin\n" version = self.version.to_i if version < set.app.database_version version = set.app.database_version + 1 end while true break unless set.app.current_migrations.any? {|migration| migration.original_version == version } version = version + 1 end set.app.create_migration! version, name, content end |
#imported? ⇒ Boolean
29 30 31 |
# File 'lib/migrext/migration.rb', line 29 def imported? set.app.current_migrations.include?(self) end |
#inspect ⇒ Object
58 59 60 |
# File 'lib/migrext/migration.rb', line 58 def inspect "#<MigrExt::Migration #@version/#@name/#@plugin original[#@original_version/#@original_name/#@original_plugin] @set=#{@set.name.inspect}>" end |