Class: PgDumper
- Inherits:
-
Object
- Object
- PgDumper
- Defined in:
- lib/pg_dumper.rb,
lib/pg_dumper/railtie.rb,
lib/pg_dumper/version.rb
Defined Under Namespace
Classes: Railtie
Constant Summary collapse
- VERSION =
"0.1.9"
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#output ⇒ Object
Returns the value of attribute output.
Instance Method Summary collapse
- #args ⇒ Object
- #clean! ⇒ Object
- #command ⇒ Object
- #compress!(level = 9) ⇒ Object
- #connection=(opts) ⇒ Object (also: #auth=)
- #create! ⇒ Object
- #data_only! ⇒ Object
-
#initialize(database, binary = nil) ⇒ PgDumper
constructor
A new instance of PgDumper.
- #output? ⇒ Boolean
- #pretty! ⇒ Object
- #run(mode = :silent) ⇒ Object
- #schema_only! ⇒ Object
- #silent! ⇒ Object
- #skip_owner! ⇒ Object
- #tempfile ⇒ Object
- #verbose! ⇒ Object
Constructor Details
#initialize(database, binary = nil) ⇒ PgDumper
Returns a new instance of PgDumper.
11 12 13 14 15 16 |
# File 'lib/pg_dumper.rb', line 11 def initialize database, binary = nil @database = database or raise "no database given" @args = [] @options = {} @binary = binary end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
8 9 10 |
# File 'lib/pg_dumper.rb', line 8 def database @database end |
#output ⇒ Object
Returns the value of attribute output.
9 10 11 |
# File 'lib/pg_dumper.rb', line 9 def output @output end |
Instance Method Details
#args ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/pg_dumper.rb', line 104 def args if output? @args.dup.push('-f', output) else @args end end |
#clean! ⇒ Object
43 44 45 |
# File 'lib/pg_dumper.rb', line 43 def clean! add_args "-c" end |
#command ⇒ Object
31 32 33 |
# File 'lib/pg_dumper.rb', line 31 def command Escape.shell_command([binary, args, database].flatten).to_s end |
#compress!(level = 9) ⇒ Object
52 53 54 |
# File 'lib/pg_dumper.rb', line 52 def compress! level=9 add_args '-Z', level if level end |
#connection=(opts) ⇒ Object Also known as: auth=
75 76 77 78 79 |
# File 'lib/pg_dumper.rb', line 75 def connection= opts add_args('-p', opts['port']) if opts['port'] add_args('-h', opts['host']) if opts['host'] add_args('-U', opts['username']) if opts['host'] end |
#create! ⇒ Object
39 40 41 |
# File 'lib/pg_dumper.rb', line 39 def create! add_args "-C" end |
#data_only! ⇒ Object
47 48 49 50 |
# File 'lib/pg_dumper.rb', line 47 def data_only! add_args "-a", '--disable-triggers' add_args '-T', 'schema_migrations' end |
#output? ⇒ Boolean
86 87 88 |
# File 'lib/pg_dumper.rb', line 86 def output? !!@output end |
#pretty! ⇒ Object
61 62 63 |
# File 'lib/pg_dumper.rb', line 61 def pretty! add_args '--column-inserts' end |
#run(mode = :silent) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pg_dumper.rb', line 18 def run(mode = :silent) raise "ERROR: pg_dump executable not found" unless binary = {} case mode when :silent [:out] = "/dev/null" end execute command, end |
#schema_only! ⇒ Object
35 36 37 |
# File 'lib/pg_dumper.rb', line 35 def schema_only! add_args "-s" end |
#silent! ⇒ Object
69 70 71 72 73 |
# File 'lib/pg_dumper.rb', line 69 def silent! # FIXME: this is not windows friendly # try to use same solution as Bundler::NULL @stderr = "/dev/null" end |
#skip_owner! ⇒ Object
65 66 67 |
# File 'lib/pg_dumper.rb', line 65 def skip_owner! add_args '--no-owner' end |
#tempfile ⇒ Object
100 101 102 |
# File 'lib/pg_dumper.rb', line 100 def tempfile @tempfile ||= new_tempfile end |
#verbose! ⇒ Object
56 57 58 59 |
# File 'lib/pg_dumper.rb', line 56 def verbose! @stderr = nil add_args "-v" end |