Class: Ardb::Migration

Inherits:
Object
  • Object
show all
Defined in:
lib/ardb/migration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(identifier) ⇒ Migration

Returns a new instance of Migration.

Raises:

  • (NoIdentifierError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/ardb/migration.rb', line 10

def initialize(identifier)
  raise NoIdentifierError if identifier.to_s.empty?

  @identifier = identifier
  @class_name = @identifier.classify.pluralize
  @file_name  = get_file_name(@identifier)
  @file_path  = File.join(Ardb.config.migrations_path, "#{@file_name}.rb")

  @source = "require 'ardb/migration_helpers'\n\n" \
            "class #{@class_name} < ActiveRecord::Migration\n" \
            "  include Ardb::MigrationHelpers\n\n" \
            "  def change\n" \
            "  end\n\n" \
            "end\n"
end

Instance Attribute Details

#class_nameObject (readonly)

Returns the value of attribute class_name.



7
8
9
# File 'lib/ardb/migration.rb', line 7

def class_name
  @class_name
end

#file_nameObject (readonly)

Returns the value of attribute file_name.



7
8
9
# File 'lib/ardb/migration.rb', line 7

def file_name
  @file_name
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



7
8
9
# File 'lib/ardb/migration.rb', line 7

def file_path
  @file_path
end

#identifierObject (readonly)

Returns the value of attribute identifier.



7
8
9
# File 'lib/ardb/migration.rb', line 7

def identifier
  @identifier
end

#sourceObject (readonly)

Returns the value of attribute source.



8
9
10
# File 'lib/ardb/migration.rb', line 8

def source
  @source
end

Instance Method Details

#save!Object



26
27
28
29
30
# File 'lib/ardb/migration.rb', line 26

def save!
  FileUtils.mkdir_p Ardb.config.migrations_path
  File.open(self.file_path, 'w'){ |f| f.write(self.source) }
  self
end