Class: DumpFile
- Inherits:
-
Object
- Object
- DumpFile
- Defined in:
- lib/psql_toys/template/dumps/_dump_file.rb
Overview
Class for single DB dump file
Constant Summary collapse
- DB_DUMP_TIMESTAMP =
'%Y-%m-%d_%H-%M'- DB_DUMP_TIMESTAMP_REGEXP_MAP =
{ 'Y' => '\d{4}', 'm' => '\d{2}', 'd' => '\d{2}', 'H' => '\d{2}', 'M' => '\d{2}' }.freeze
- DB_DUMP_TIMESTAMP_REGEXP =
DB_DUMP_TIMESTAMP_REGEXP_MAP .each_with_object(DB_DUMP_TIMESTAMP.dup) do |(key, value), result| result.gsub! "%#{key}", value end
- DB_DUMP_EXTENSIONS =
{ 'plain' => '.sql', 'custom' => '.dump' }.freeze
Class Attribute Summary collapse
-
.db_config ⇒ Object
Returns the value of attribute db_config.
-
.db_dumps_dir ⇒ Object
Returns the value of attribute db_dumps_dir.
Instance Attribute Summary collapse
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(filename: nil, format: 'custom') ⇒ DumpFile
constructor
A new instance of DumpFile.
- #path ⇒ Object
- #print ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(filename: nil, format: 'custom') ⇒ DumpFile
Returns a new instance of DumpFile.
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/psql_toys/template/dumps/_dump_file.rb', line 77 def initialize(filename: nil, format: 'custom') if filename @extension = File.extname(filename) @format = DB_DUMP_EXTENSIONS.key(@extension) self.version = filename[/#{DB_DUMP_TIMESTAMP_REGEXP}/o] else @format = format @extension = DB_DUMP_EXTENSIONS[@format] self. = Time.now end end |
Class Attribute Details
.db_config ⇒ Object
Returns the value of attribute db_config.
49 50 51 |
# File 'lib/psql_toys/template/dumps/_dump_file.rb', line 49 def db_config @db_config end |
.db_dumps_dir ⇒ Object
Returns the value of attribute db_dumps_dir.
49 50 51 |
# File 'lib/psql_toys/template/dumps/_dump_file.rb', line 49 def db_dumps_dir @db_dumps_dir end |
Instance Attribute Details
#format ⇒ Object (readonly)
Returns the value of attribute format.
75 76 77 |
# File 'lib/psql_toys/template/dumps/_dump_file.rb', line 75 def format @format end |
#timestamp ⇒ Object
Returns the value of attribute timestamp.
75 76 77 |
# File 'lib/psql_toys/template/dumps/_dump_file.rb', line 75 def @timestamp end |
#version ⇒ Object
Returns the value of attribute version.
75 76 77 |
# File 'lib/psql_toys/template/dumps/_dump_file.rb', line 75 def version @version end |
Class Method Details
.all ⇒ Object
67 68 69 70 71 72 |
# File 'lib/psql_toys/template/dumps/_dump_file.rb', line 67 def all Dir[File.join(db_dumps_dir, '*')] .grep(db_dump_regexp) .map! { |file| new filename: file } .sort! end |
.db_dump_regexp ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/psql_toys/template/dumps/_dump_file.rb', line 51 def db_dump_regexp return unless db_config return @db_dump_regexp if defined?(@db_dump_regexp) regexp_escaped_db_dump_extensions = DB_DUMP_EXTENSIONS.values.map do |db_dump_extension| Regexp.escape(db_dump_extension) end @db_dump_regexp = /^ #{db_dumps_dir}#{Regexp.escape(File::SEPARATOR)} #{db_config[:database]}_#{DB_DUMP_TIMESTAMP_REGEXP} (#{regexp_escaped_db_dump_extensions.join('|')}) $/xo end |
Instance Method Details
#<=>(other) ⇒ Object
89 90 91 |
# File 'lib/psql_toys/template/dumps/_dump_file.rb', line 89 def <=>(other) <=> other. end |
#path ⇒ Object
101 102 103 |
# File 'lib/psql_toys/template/dumps/_dump_file.rb', line 101 def path File.join self.class.db_dumps_dir, "#{self.class.db_config[:database]}_#{version}#{@extension}" end |
#print ⇒ Object
97 98 99 |
# File 'lib/psql_toys/template/dumps/_dump_file.rb', line 97 def print puts self end |
#to_s ⇒ Object
93 94 95 |
# File 'lib/psql_toys/template/dumps/_dump_file.rb', line 93 def to_s "#{} #{format}" end |