Class: Ardb::Migration
- Inherits:
-
Object
- Object
- Ardb::Migration
- Defined in:
- lib/ardb/migration.rb
Constant Summary collapse
- NoIdentifierError =
Class.new(ArgumentError)
Instance Attribute Summary collapse
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#migrations_path ⇒ Object
readonly
Returns the value of attribute migrations_path.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(ardb_config, identifier) ⇒ Migration
constructor
A new instance of Migration.
- #save! ⇒ Object
Constructor Details
#initialize(ardb_config, identifier) ⇒ Migration
Returns a new instance of Migration.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ardb/migration.rb', line 12 def initialize(ardb_config, identifier) raise NoIdentifierError if identifier.to_s.empty? @migrations_path = ardb_config.migrations_path @identifier = identifier @class_name = @identifier.classify.pluralize @file_name = get_file_name(@identifier) @file_path = File.join(migrations_path, "#{@file_name}.rb") migration_version = ActiveRecord::Migration.current_version @source = "class #{@class_name} "\ "< ActiveRecord::Migration[#{migration_version}]\n"\ " def change\n"\ " end\n"\ "end\n" end |
Instance Attribute Details
#class_name ⇒ Object (readonly)
Returns the value of attribute class_name.
10 11 12 |
# File 'lib/ardb/migration.rb', line 10 def class_name @class_name end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
10 11 12 |
# File 'lib/ardb/migration.rb', line 10 def file_name @file_name end |
#file_path ⇒ Object (readonly)
Returns the value of attribute file_path.
10 11 12 |
# File 'lib/ardb/migration.rb', line 10 def file_path @file_path end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
9 10 11 |
# File 'lib/ardb/migration.rb', line 9 def identifier @identifier end |
#migrations_path ⇒ Object (readonly)
Returns the value of attribute migrations_path.
9 10 11 |
# File 'lib/ardb/migration.rb', line 9 def migrations_path @migrations_path end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
10 11 12 |
# File 'lib/ardb/migration.rb', line 10 def source @source end |
Instance Method Details
#save! ⇒ Object
31 32 33 34 35 |
# File 'lib/ardb/migration.rb', line 31 def save! FileUtils.mkdir_p migrations_path File.open(file_path, "w"){ |f| f.write(source) } self end |