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.5"
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
- #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
94 95 96 97 98 99 100 |
# File 'lib/pg_dumper.rb', line 94 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]).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=
71 72 73 74 75 |
# File 'lib/pg_dumper.rb', line 71 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
82 83 84 |
# File 'lib/pg_dumper.rb', line 82 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
65 66 67 68 69 |
# File 'lib/pg_dumper.rb', line 65 def silent! # FIXME: this is not windows friendly # try to use same solution as Bundler::NULL @stderr = "/dev/null" end |
#tempfile ⇒ Object
90 91 92 |
# File 'lib/pg_dumper.rb', line 90 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 |