Class: Capistrano::DBSync::Postgres::FileNameGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/db_sync/postgres/file_name_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileNameGenerator

Returns a new instance of FileNameGenerator.



2
3
4
5
# File 'lib/capistrano/db_sync/postgres/file_name_generator.rb', line 2

def initialize(path)
  @path = path
  @sequence = 0
end

Class Method Details

.extract_name(file_path) ⇒ Object



18
19
20
21
# File 'lib/capistrano/db_sync/postgres/file_name_generator.rb', line 18

def self.extract_name(file_path)
  file_name = File.basename(file_path)
  file_name.scan(/\d+-(.*)\.(schema|table)$/).flatten.first
end

Instance Method Details

#next(name, extension) ⇒ Object

Generates sequential file names. Examples: next(“faceburger”, :schema) => 0001-faceburger.schema next(“posts”, :table) => 0002-posts.table next(“comments”, :table) => 0003-comments.table

Raises:

  • (ArgumentError)


12
13
14
15
16
# File 'lib/capistrano/db_sync/postgres/file_name_generator.rb', line 12

def next(name, extension)
  raise ArgumentError unless [:schema, :table].include?(extension)
  @sequence += 1
  File.join(@path, "%04i-#{name}.#{extension}" % @sequence)
end