Class: PgExport::Dump
Constant Summary
collapse
- TIMESTAMP =
'_%Y%m%d_%H%M%S'.freeze
- CHUNK_SIZE =
(2**16).freeze
Roles::HumanReadable::MAPPING
Instance Attribute Summary collapse
Instance Method Summary
collapse
#size_human
Constructor Details
#initialize(name:, db_name:) ⇒ Dump
Returns a new instance of Dump.
19
20
21
22
|
# File 'lib/pg_export/dump.rb', line 19
def initialize(name:, db_name:)
@name, @db_name = name, db_name
@timestamp = Time.now.strftime(TIMESTAMP)
end
|
Instance Attribute Details
#db_name ⇒ Object
Returns the value of attribute db_name.
17
18
19
|
# File 'lib/pg_export/dump.rb', line 17
def db_name
@db_name
end
|
#name ⇒ Object
Returns the value of attribute name.
17
18
19
|
# File 'lib/pg_export/dump.rb', line 17
def name
@name
end
|
Instance Method Details
#each_chunk ⇒ Object
36
37
38
39
40
|
# File 'lib/pg_export/dump.rb', line 36
def each_chunk
open(:read) do |file|
yield file.read(CHUNK_SIZE) until file.eof?
end
end
|
#ext ⇒ Object
24
25
26
|
# File 'lib/pg_export/dump.rb', line 24
def ext
''
end
|
#open(operation_type, &block) ⇒ Object
28
29
30
31
32
33
34
|
# File 'lib/pg_export/dump.rb', line 28
def open(operation_type, &block)
case operation_type.to_sym
when :read then File.open(path, 'r', &block)
when :write then File.open(path, 'w', &block)
else raise ArgumentError, 'Operation type can be only :read or :write'
end
end
|
#timestamped_name ⇒ Object
42
43
44
|
# File 'lib/pg_export/dump.rb', line 42
def timestamped_name
db_name + timestamp + ext
end
|
#to_s ⇒ Object
46
47
48
|
# File 'lib/pg_export/dump.rb', line 46
def to_s
"#{name} (#{size_human})"
end
|