rumination 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1fa5a4f014b31f64ce973302f5794affb50fff7b
4
- data.tar.gz: 42bf01305a89bf12447635f14b39d7311950b740
3
+ metadata.gz: 3796abee1e89f550d0afc421dbfb7cbf6e9398ca
4
+ data.tar.gz: 0099071ff01dfa452b382c4425df6b6afc9eca3d
5
5
  SHA512:
6
- metadata.gz: fbbbf15b96f7a299b48e0a8edad6eb2902b38b9777b6d51ca4538bd8a92b41d426d020a596d05ade82a1b2683995c6a8fd0ef4ac6b1657c011c74d95ee3a3582
7
- data.tar.gz: 2d82cee2004bca4c186bd0c978a213d002c88e9d1f027e8dbccd812d3ab88ca92dc128481cf03cdf1fe286596bacd26fafd639495edff2f273d48cb43a5966d9
6
+ metadata.gz: 84ef7e03718acca0806c0c1822489746a4a2a898ee826a9cb3f61ef40902b24ce36e4c5f5a7af9dbf24a2b2efe54d0fbae730a3c3119c773f90790683485a24f
7
+ data.tar.gz: b3b1466d3ea9e39671f47c4ff4a187972aa89155fcb73ea05fdbc4a8785910030e5df1cd24f5cf01b8c3f8f219770c36d359710f72ba9068ec8eee075f70a70b
@@ -0,0 +1,18 @@
1
+ module Rumination
2
+ module Pg
3
+ # include this module into something with #sh, e.g. next to Rake::FileUtils
4
+ module Commands
5
+ def pg_dump *args
6
+ sh "pg_dump #{args.join(" ")}"
7
+ end
8
+
9
+ def pg_restore *args
10
+ Pg::Restore.call *args, "-d", ENV["PGDATABASE"]
11
+ end
12
+
13
+ def rsync *args
14
+ sh "rsync #{args.join(" ")}"
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,67 @@
1
+ module Rumination
2
+ module Pg
3
+ class Restore
4
+ attr_reader :args
5
+
6
+ def initialize *args
7
+ @args = @args.dup.freeze
8
+ end
9
+
10
+ def self.call *args
11
+ new(*args).call
12
+ end
13
+
14
+ def call
15
+ command = "pg_restore #{args.join(" ")}"
16
+ puts command
17
+ Open3.popen3 ENV, command do |stdin, stdout, stderr, thread|
18
+ out_lines = stdout.readlines
19
+ err_lines = stderr.readlines
20
+ save_stream :stdout, out_lines
21
+ save_stream :stderr, err_lines
22
+ puts_log out_lines + err_lines, indent: 2
23
+ analyse_stderr! err_lines
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def puts_log lines, indent: 0
30
+ lines = lines.dup
31
+ lines[3..-4] = ["", "... snip snip ...", ""] unless lines.count < 8
32
+ lines.each do |line|
33
+ puts line.indent(indent)
34
+ end
35
+ end
36
+
37
+ def analyse_stderr! lines
38
+ text = lines.join("\n")
39
+ error_count = text.scan(/ERROR/).count
40
+ more_errors_than_ignored = error_count > 0 && !expected_errors?(text, error_count)
41
+ other_errors = error_matchers.any?{|m| m === text}
42
+ if more_errors_than_ignored || other_errors
43
+ raise RuntimeError, "pg_restore seems to have failed"
44
+ end
45
+ end
46
+
47
+ def save_stream name, lines
48
+ File.open("log/pg_restore.#{name}.log","w") do |io|
49
+ io.puts lines
50
+ end
51
+ end
52
+
53
+ def save_streams out_lines, err_lines
54
+ end
55
+
56
+ def error_matchers
57
+ [
58
+ /could not open input file/
59
+ ]
60
+ end
61
+
62
+ def expected_errors? text, count
63
+ text =~ /WARNING: errors ignored on restore: #{count}/
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1 @@
1
+ require_relative "pg/commands"
@@ -1,3 +1,3 @@
1
1
  module Rumination
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/rumination.rb CHANGED
@@ -1,5 +1,6 @@
1
- require "rumination/version"
2
- require "rumination/dev_user"
3
-
4
1
  module Rumination
5
2
  end
3
+
4
+ require_relative "rumination/version"
5
+ require_relative "rumination/dev_user"
6
+ require_relative "rumination/pg"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rumination
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Baguinski
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-15 00:00:00.000000000 Z
11
+ date: 2017-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,6 +84,9 @@ files:
84
84
  - bin/setup
85
85
  - lib/rumination.rb
86
86
  - lib/rumination/dev_user.rb
87
+ - lib/rumination/pg.rb
88
+ - lib/rumination/pg/commands.rb
89
+ - lib/rumination/pg/restore.rb
87
90
  - lib/rumination/version.rb
88
91
  - rumination.gemspec
89
92
  homepage: https://github.com/artm/rumination