postmodern 0.0.10 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c873bca7e7b892917fe6b1d1e0f322985419209c
4
- data.tar.gz: a183be591075d4c67948124695ad69da0c3e35e3
3
+ metadata.gz: 15bd95a1daf5a24f06fcfa1645094b3bd1a76c0c
4
+ data.tar.gz: 60aeb0096180e784f4e13e812075319523609823
5
5
  SHA512:
6
- metadata.gz: bf053810004c5e3a9e6f1876d95e90996d23ad4134ef6f06893b101e88701c1e7d75e24d344a6f97fb3ffdb853581221cd47ecdd88823c9065dfa01fa4aa602e
7
- data.tar.gz: c49137fac8a2fed972ce655364e69fdf63aea8a8aac3fba6925acc9e1872a2a6bf595a65f2b0690dca5cba754b7c6285346d7f3110b6d4c504f7e93a81c1003e
6
+ metadata.gz: fac44addd806dc9688c1cf5a076c2bed5b6ebf6aa44c58d1c78357a9c4046b3735aa13317b0fa890546f6202d054c3a2971bfb7806c09b4cfa5f13a78a16b0f0
7
+ data.tar.gz: bc2afb31d22804a418ed917b5bae2d1422cf4740b41ab3cdab0508a4edbaa2a12566afde2c6c445e16fc6f3e5c51504e4d211230baa59e0281c0a6be8adcb836
data/bin/postmodern CHANGED
@@ -2,38 +2,6 @@
2
2
 
3
3
  $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
4
 
5
- require 'postmodern/errors'
6
- require 'postmodern/wal'
7
- require 'optparse'
5
+ require 'postmodern/runner'
8
6
 
9
- options = {}
10
- parser = OptionParser.new do |opts|
11
- opts.banner = "Usage: postmodern (archive|restore) <options>"
12
-
13
- opts.on('-f', '--filename FILE', 'File name to archive') do |o|
14
- options[:file] = o
15
- end
16
-
17
- opts.on('-p', '--path PATH', 'Path name of file to archive') do |o|
18
- options[:path] = o
19
- end
20
-
21
- opts.on_tail("-h", "--help", "Show this message") do
22
- puts opts
23
- exit
24
- end
25
-
26
- opts.on_tail("--version", "Show version") do
27
- require 'postmodern/version'
28
- puts Postmodern::VERSION
29
- exit
30
- end
31
- end
32
- parser.parse!
33
-
34
- begin
35
- Postmodern::WAL.run(ARGV.first, options)
36
- rescue Postmodern::Error => e
37
- puts e.message
38
- puts parser.to_s
39
- end
7
+ Postmodern::Runner.run(ARGV)
data/lib/postmodern.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require "postmodern/version"
2
2
 
3
3
  module Postmodern
4
- # Your code goes here...
5
4
  end
@@ -0,0 +1,37 @@
1
+ require 'optparse'
2
+
3
+ module Postmodern
4
+ class Command
5
+ def self.required_options
6
+ @required_options ||= []
7
+ end
8
+
9
+ def parser
10
+ OptionParser.new
11
+ end
12
+
13
+ attr_reader :options
14
+
15
+ def initialize(args)
16
+ @options = {}
17
+
18
+ parse_args(args)
19
+ validate!
20
+ end
21
+
22
+ def run
23
+ end
24
+
25
+ def validate!
26
+ if (self.class.required_options - self.options.keys).any?
27
+ puts parser
28
+ exit 1
29
+ end
30
+ end
31
+
32
+ def parse_args(args)
33
+ parser.parse!(args)
34
+ self.options
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ require 'postmodern/command'
2
+
3
+ module Postmodern
4
+ class Dummy < Command
5
+ def parser
6
+ @parser ||= OptionParser.new do |opts|
7
+ opts.banner = "Usage: postmodern <command> <options>"
8
+
9
+ opts.separator ""
10
+ opts.separator "Available commands:"
11
+ opts.separator " archive"
12
+ opts.separator " restore"
13
+ opts.separator ""
14
+ opts.separator "Options:"
15
+
16
+ opts.on_tail("-h", "--help", "Show this message") do
17
+ puts opts
18
+ exit
19
+ end
20
+
21
+ opts.on_tail("--version", "Show version") do
22
+ require 'postmodern/version'
23
+ puts Postmodern::VERSION
24
+ exit
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ require 'postmodern/wal'
2
+ require 'postmodern/dummy'
3
+
4
+ module Postmodern
5
+ module Runner
6
+ attr_reader :argv
7
+
8
+ DEFAULT_COMMAND = Dummy
9
+ COMMAND_MAP = {
10
+ 'archive' => WAL::Archive,
11
+ 'restore' => WAL::Restore
12
+ }.freeze
13
+
14
+ def self.run(args)
15
+ command_for(args.first).new(args).run
16
+ end
17
+
18
+ def self.command_for(command)
19
+ COMMAND_MAP[command] || DEFAULT_COMMAND
20
+ end
21
+ end
22
+ end
@@ -1,3 +1,3 @@
1
1
  module Postmodern
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
@@ -1,23 +1,3 @@
1
1
  require 'postmodern/wal/archive'
2
2
  require 'postmodern/wal/restore'
3
- require 'postmodern/errors'
4
3
 
5
- module Postmodern
6
- module WAL
7
- COMMANDS = {
8
- 'archive' => Postmodern::WAL::Archive,
9
- 'restore' => Postmodern::WAL::Restore
10
- }
11
-
12
- def self.run(command, options)
13
- validate!(options)
14
- COMMANDS[command].new(options[:file], options[:path]).run
15
- end
16
-
17
- def self.validate!(options)
18
- unless options[:file] and options[:path]
19
- raise Postmodern::Error.new('Missing required options')
20
- end
21
- end
22
- end
23
- end
@@ -1,8 +1,64 @@
1
- require_relative 'base'
1
+ require 'postmodern/command'
2
2
 
3
3
  module Postmodern
4
4
  module WAL
5
- class Archive < Base
5
+ class Archive < Postmodern::Command
6
+ required_options << :file
7
+ required_options << :path
8
+
9
+ def parser
10
+ @parser ||= OptionParser.new do |opts|
11
+ opts.banner = "Usage: postmodern (archive|restore) <options>"
12
+
13
+ opts.on('-f', '--filename FILE', 'File name of xlog') do |o|
14
+ self.options[:file] = o
15
+ end
16
+
17
+ opts.on('-p', '--path PATH', 'Path of xlog file') do |o|
18
+ self.options[:path] = o
19
+ end
20
+
21
+ opts.on_tail("-h", "--help", "Show this message") do
22
+ puts opts
23
+ exit
24
+ end
25
+
26
+ opts.on_tail("--version", "Show version") do
27
+ require 'postmodern/version'
28
+ puts Postmodern::VERSION
29
+ exit
30
+ end
31
+ end
32
+ end
33
+
34
+ def run
35
+ if local_script_exists?
36
+ IO.popen("#{local_script} #{path} #{filename}",
37
+ env: {
38
+ 'WAL_ARCHIVE_PATH' => path,
39
+ 'WAL_ARCHIVE_FILE' => filename,
40
+ 'PATH' => ENV['PATH']
41
+ }) { |f| puts f.gets }
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def path
48
+ @options[:path]
49
+ end
50
+
51
+ def filename
52
+ @options[:file]
53
+ end
54
+
55
+ def local_script_exists?
56
+ system({'PATH' => ENV['PATH']}, "which #{local_script} >/dev/null 2>/dev/null")
57
+ end
58
+
59
+ def local_script
60
+ 'postmodern_archive.local'
61
+ end
6
62
  end
7
63
  end
8
64
  end
@@ -1,8 +1,8 @@
1
- require_relative 'base'
1
+ require_relative 'archive'
2
2
 
3
3
  module Postmodern
4
4
  module WAL
5
- class Restore < Base
5
+ class Restore < Archive
6
6
  private
7
7
 
8
8
  def local_script
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'archive help' do
4
+ it 'responds' do
5
+ expect(`bin/postmodern archive --help`).to eq <<-END
6
+ Usage: postmodern (archive|restore) <options>
7
+ -f, --filename FILE File name of xlog
8
+ -p, --path PATH Path of xlog file
9
+ -h, --help Show this message
10
+ --version Show version
11
+ END
12
+ end
13
+ end
14
+
15
+ describe 'archive' do
16
+ let(:command) { `bin/postmodern archive --path filepath --filename filename` }
17
+
18
+ let(:usage) { <<-END
19
+ Usage: postmodern (archive|restore) <options>
20
+ -f, --filename FILE File name of xlog
21
+ -p, --path PATH Path of xlog file
22
+ -h, --help Show this message
23
+ --version Show version
24
+ END
25
+ }
26
+
27
+ before do
28
+ double_cmd('postmodern_archive.local', exit: 0)
29
+ end
30
+
31
+ describe 'validations' do
32
+ context 'with no --path' do
33
+ let(:command) { `bin/postmodern archive --filename filename` }
34
+
35
+ it 'fails' do
36
+ expect { command }.to have_exit_status(1)
37
+ end
38
+
39
+ it 'prints usage' do
40
+ expect(command).to eq(usage)
41
+ end
42
+ end
43
+
44
+ context 'with no --filename' do
45
+ let(:command) { `bin/postmodern archive --path path` }
46
+
47
+ it 'fails' do
48
+ expect { command }.to have_exit_status(1)
49
+ end
50
+
51
+ it 'prints usage' do
52
+ expect(command).to eq(usage)
53
+ end
54
+ end
55
+ end
56
+
57
+ context 'when local script is present' do
58
+ before { double_cmd('which postmodern_archive.local', exit: 0) }
59
+
60
+ it 'succeeds' do
61
+ expect { command }.to have_exit_status(0)
62
+ end
63
+
64
+ it 'calls a local file with file name and path' do
65
+ expect { command }.to shellout('postmodern_archive.local filepath filename')
66
+ end
67
+ end
68
+
69
+ context 'when local script is not present' do
70
+ before { double_cmd('which postmodern_archive.local', exit: 1) }
71
+
72
+ it 'succeeds' do
73
+ expect { command }.to have_exit_status(0)
74
+ end
75
+
76
+ it 'does nothing' do
77
+ expect { command }.not_to shellout('pg_wal_archive.local filepath filename')
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+ require 'postmodern/version'
3
+
4
+ describe 'dummy help' do
5
+ it 'responds with usage info' do
6
+ expect(`bin/postmodern --help`).to eq <<-END
7
+ Usage: postmodern <command> <options>
8
+
9
+ Available commands:
10
+ archive
11
+ restore
12
+
13
+ Options:
14
+ -h, --help Show this message
15
+ --version Show version
16
+ END
17
+ end
18
+ end
19
+
20
+ describe 'dummy version' do
21
+ it 'responds with the Postmodern version' do
22
+ expect(`bin/postmodern --version`).to match(Postmodern::VERSION)
23
+ end
24
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'restore help' do
4
+ it 'responds' do
5
+ expect(`bin/postmodern restore --help`).to eq <<-END
6
+ Usage: postmodern (archive|restore) <options>
7
+ -f, --filename FILE File name of xlog
8
+ -p, --path PATH Path of xlog file
9
+ -h, --help Show this message
10
+ --version Show version
11
+ END
12
+ end
13
+ end
14
+
15
+ describe 'restore' do
16
+ let(:command) { `bin/postmodern restore --path filepath --filename filename` }
17
+
18
+ before do
19
+ double_cmd('postmodern_restore.local')
20
+ end
21
+
22
+ context 'when local script is present' do
23
+ before { double_cmd('which', exit: 0) }
24
+
25
+ it 'succeeds' do
26
+ expect { command }.to have_exit_status(0)
27
+ end
28
+
29
+ it 'calls a local file with file name and path' do
30
+ expect { command }.to shellout('postmodern_restore.local filepath filename')
31
+ end
32
+ end
33
+
34
+ context 'when local script is not present' do
35
+ before { double_cmd('which', exit: 1) }
36
+
37
+ it 'succeeds' do
38
+ expect { command }.to have_exit_status(0)
39
+ end
40
+
41
+ it 'does nothing' do
42
+ expect { command }.not_to shellout('pg_wal_restore.local filepath filename')
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+ require 'postmodern/runner'
3
+
4
+ describe Postmodern::Runner do
5
+
6
+ describe '.command' do
7
+ it 'chooses archiver' do
8
+ expect(Postmodern::Runner.command_for('archive')).to be Postmodern::WAL::Archive
9
+ end
10
+
11
+ it 'chooses restorer' do
12
+ expect(Postmodern::Runner.command_for('restore')).to be Postmodern::WAL::Restore
13
+ end
14
+
15
+ it 'defaults to dummy' do
16
+ expect(Postmodern::Runner.command_for('ljfaldf')).to be Postmodern::Dummy
17
+ end
18
+ end
19
+
20
+ describe '.run' do
21
+ it 'runs the command class' do
22
+ args = ['blahrgh', 'first', 'second']
23
+ dummy_class = double
24
+ expect(Postmodern::Runner).to receive(:command_for).and_return(dummy_class)
25
+ expect(dummy_class).to receive(:new).with(args).and_return(dummy_class)
26
+ expect(dummy_class).to receive(:run)
27
+ Postmodern::Runner.run(args)
28
+ end
29
+ end
30
+ end
@@ -6,8 +6,9 @@ describe Postmodern::WAL::Archive do
6
6
 
7
7
  let(:filename) { "some_file" }
8
8
  let(:path) { "/path/to/file" }
9
+ let(:arguments) { %W(--filename #{filename} --path #{path}) }
9
10
 
10
- subject(:archiver) { Postmodern::WAL::Archive.new(filename, path) }
11
+ subject(:archiver) { Postmodern::WAL::Archive.new(arguments) }
11
12
 
12
13
  describe '#run' do
13
14
  let(:expected_command) { "postmodern_archive.local #{path} #{filename}" }
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+ require 'postmodern/wal/restore'
3
+
4
+ describe Postmodern::WAL::Restore do
5
+ before { allow(IO).to receive(:popen) }
6
+
7
+ let(:filename) { "some_file" }
8
+ let(:path) { "/path/to/file" }
9
+ let(:arguments) { %W(--filename #{filename} --path #{path}) }
10
+
11
+ subject(:restorer) { Postmodern::WAL::Restore.new(arguments) }
12
+
13
+ describe '#run' do
14
+ let(:expected_command) { "postmodern_restore.local #{path} #{filename}" }
15
+
16
+ context 'when local script exists' do
17
+ before { double_cmd('which postmodern_restore.local', exit: 0) }
18
+
19
+ it 'executes postmodern_restore.local with filename and path' do
20
+ restorer.run
21
+ expect(IO).to have_received(:popen).with(expected_command, env:
22
+ {
23
+ 'WAL_ARCHIVE_PATH' => path,
24
+ 'WAL_ARCHIVE_FILE' => filename,
25
+ 'PATH' => anything
26
+ }
27
+ )
28
+ end
29
+ end
30
+
31
+ context 'when local script does not exist' do
32
+ before { double_cmd('which postmodern_restore.local', exit: 1) }
33
+
34
+ it 'executes postmodern_restore.local with filename and path' do
35
+ restorer.run
36
+ expect(IO).not_to have_received(:popen)
37
+ end
38
+ end
39
+ end
40
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmodern
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Saxby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-28 00:00:00.000000000 Z
11
+ date: 2014-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,15 +56,20 @@ files:
56
56
  - Rakefile
57
57
  - bin/postmodern
58
58
  - lib/postmodern.rb
59
- - lib/postmodern/errors.rb
59
+ - lib/postmodern/command.rb
60
+ - lib/postmodern/dummy.rb
61
+ - lib/postmodern/runner.rb
60
62
  - lib/postmodern/version.rb
61
63
  - lib/postmodern/wal.rb
62
64
  - lib/postmodern/wal/archive.rb
63
- - lib/postmodern/wal/base.rb
64
65
  - lib/postmodern/wal/restore.rb
65
66
  - postmodern.gemspec
66
- - spec/bin/postmodern_spec.rb
67
+ - spec/features/archive_spec.rb
68
+ - spec/features/dummy_spec.rb
69
+ - spec/features/restore_spec.rb
70
+ - spec/postmodern/runner_spec.rb
67
71
  - spec/postmodern/wal/archive_spec.rb
72
+ - spec/postmodern/wal/restore_spec.rb
68
73
  - spec/spec_helper.rb
69
74
  homepage: https://github.com/wanelo/postmodern
70
75
  licenses:
@@ -91,7 +96,11 @@ signing_key:
91
96
  specification_version: 4
92
97
  summary: Tools for managing PostgreSQL
93
98
  test_files:
94
- - spec/bin/postmodern_spec.rb
99
+ - spec/features/archive_spec.rb
100
+ - spec/features/dummy_spec.rb
101
+ - spec/features/restore_spec.rb
102
+ - spec/postmodern/runner_spec.rb
95
103
  - spec/postmodern/wal/archive_spec.rb
104
+ - spec/postmodern/wal/restore_spec.rb
96
105
  - spec/spec_helper.rb
97
106
  has_rdoc:
@@ -1,4 +0,0 @@
1
- module Postmodern
2
- class Error < StandardError
3
- end
4
- end
@@ -1,34 +0,0 @@
1
- module Postmodern
2
- module WAL
3
- class Base
4
- attr_reader :filename, :path
5
-
6
- def initialize(filename, path)
7
- @filename = filename
8
- @path = path
9
- end
10
-
11
- def run
12
- if local_script_exists?
13
- IO.popen("#{local_script} #{path} #{filename}",
14
- env: {
15
- 'WAL_ARCHIVE_PATH' => path,
16
- 'WAL_ARCHIVE_FILE' => filename,
17
- 'PATH' => ENV['PATH']
18
- })
19
- end
20
- end
21
-
22
- private
23
-
24
- def local_script_exists?
25
- `which #{local_script} >/dev/null 2>/dev/null`
26
- $?.exitstatus == 0
27
- end
28
-
29
- def local_script
30
- 'postmodern_archive.local'
31
- end
32
- end
33
- end
34
- end
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'postmodern' do
4
- describe 'archive' do
5
- let(:command) { `bin/postmodern archive --path filepath --filename filename` }
6
-
7
- before do
8
- double_cmd('postmodern_archive.local')
9
- end
10
-
11
- context 'when local script is present' do
12
- before { double_cmd('which', exit: 0) }
13
-
14
- it 'succeeds' do
15
- expect { command }.to have_exit_status(0)
16
- end
17
-
18
- it 'calls a local file with file name and path' do
19
- expect { command }.to shellout('postmodern_archive.local filepath filename')
20
- end
21
- end
22
-
23
- context 'when local script is not present' do
24
- before { double_cmd('which', exit: 1) }
25
-
26
- it 'succeeds' do
27
- expect { command }.to have_exit_status(0)
28
- end
29
-
30
- it 'does nothing' do
31
- expect { command }.not_to shellout('pg_wal_archive.local filepath filename')
32
- end
33
- end
34
- end
35
-
36
- describe 'restore' do
37
- let(:command) { `bin/postmodern restore --path filepath --filename filename` }
38
-
39
- before do
40
- double_cmd('postmodern_restore.local')
41
- end
42
-
43
- context 'when local script is present' do
44
- before { double_cmd('which', exit: 0) }
45
-
46
- it 'succeeds' do
47
- expect { command }.to have_exit_status(0)
48
- end
49
-
50
- it 'calls a local file with file name and path' do
51
- expect { command }.to shellout('postmodern_restore.local filepath filename')
52
- end
53
- end
54
-
55
- context 'when local script is not present' do
56
- before { double_cmd('which', exit: 1) }
57
-
58
- it 'succeeds' do
59
- expect { command }.to have_exit_status(0)
60
- end
61
-
62
- it 'does nothing' do
63
- expect { command }.not_to shellout('pg_wal_restore.local filepath filename')
64
- end
65
- end
66
- end
67
- end