prep_kit 0.1.0 → 0.1.1

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: 831a2389d26e74159dcacbe68fac54514e639a22
4
- data.tar.gz: f0bff29e8ec70f24df8d437e150050cda27ab882
3
+ metadata.gz: e3c72a456ade8b38e4f186ac75238ebeef64dd40
4
+ data.tar.gz: 4d07cfe6f29710834edcdebe8d5c4faa226b1b92
5
5
  SHA512:
6
- metadata.gz: d80d8256e5821f996a8862b2427a8a7dd0d99a8e3389bfa859c918b4697b1ee9f075bc21ff59f0760a553079cfe69ee49022178fb33826ac6c6d2fafa334edc2
7
- data.tar.gz: 498a326e07f001600f4b9bbca460a4df9dc99bca1125fd450f0142894f23601be117bd4e25213adbd525bae6a2386007ca4581305a36c6d20b251e4b135b91b2
6
+ metadata.gz: d6b10f620178ffd64fe29f1481282d76d05719048696f4ae9f3bc7f91f634d9349ea47e229367a92634bf7ac19b89e20892f27175445e87bd1e588a4ee3514ab
7
+ data.tar.gz: fadc062d7c17ccd5c838cb0df0f561436858639f2cb6910ad682150a9f512e8f735b0afb36b9b861337e4ee41034b9940dadff99fd74a94cf336b5f6649f4c20
data/.gitignore CHANGED
@@ -1,9 +1,7 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
1
+ *.gem
2
+ *.swp
3
+ .ruby-version
4
+ .bundle
5
+ .DS_Store
6
+ pkg
7
+ vendor/bundle
data/Gemfile.lock ADDED
@@ -0,0 +1,42 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ prep_kit (0.1.1)
5
+ remote_marshal
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ file-tail (1.1.0)
11
+ tins (~> 1.0)
12
+ net-scp (1.2.1)
13
+ net-ssh (>= 2.6.5)
14
+ net-ssh (3.0.2)
15
+ rake (10.4.2)
16
+ remote_marshal (0.1.9)
17
+ net-scp
18
+ net-ssh
19
+ sourcify
20
+ ruby2ruby (2.2.0)
21
+ ruby_parser (~> 3.1)
22
+ sexp_processor (~> 4.0)
23
+ ruby_parser (3.7.3)
24
+ sexp_processor (~> 4.1)
25
+ sexp_processor (4.6.1)
26
+ sourcify (0.5.0)
27
+ file-tail (>= 1.0.5)
28
+ ruby2ruby (>= 1.2.5)
29
+ ruby_parser (>= 2.0.5)
30
+ sexp_processor (>= 3.0.5)
31
+ tins (1.8.2)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ bundler (~> 1.10)
38
+ prep_kit!
39
+ rake (~> 10.0)
40
+
41
+ BUNDLED WITH
42
+ 1.10.6
@@ -0,0 +1,48 @@
1
+ module PrepKit
2
+ class Context
3
+ def initialize(host, user, options)
4
+ @vars = {}
5
+ @env = RemoteMarshal.new(host, user, options)
6
+ end
7
+
8
+ def task(name, &block)
9
+ raise AssignError, name if @vars[name]
10
+
11
+ @vars[name] = block
12
+ end
13
+
14
+ def load(filename)
15
+ instance_eval open(filename, &:read), filename
16
+ end
17
+
18
+ def call(name)
19
+ raise NotFoundError, name unless Proc === (block = @vars[name])
20
+
21
+ Task.new(self).action &block
22
+ end
23
+
24
+ def sh(command)
25
+ status, output, error = @env.exec!(command)
26
+
27
+ raise RuntimeError, error unless status == 0
28
+
29
+ output
30
+ end
31
+
32
+ def test?(path, option)
33
+ status, *_ = @env.test?(path, option)
34
+
35
+ status == 0
36
+ end
37
+
38
+ %i(upload download).each do |name|
39
+ define_method(name) do |src, dst|
40
+ @env.public_send("#{name}!", src, dst)
41
+ end
42
+ end
43
+
44
+ def current_directory
45
+ nil
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,42 @@
1
+ module PrepKit
2
+ class Task
3
+ def initialize(parent, directory = nil)
4
+ @parent = parent
5
+ @directory = directory
6
+ end
7
+
8
+ def sh(command)
9
+ chdir = @directory ? "cd #{@directory};" : nil
10
+
11
+ @parent.sh([chdir, command].compact.join(' '))
12
+ end
13
+
14
+ def test?(path, option)
15
+ @parent.test?(path, option)
16
+ end
17
+
18
+ def upload(src, dst)
19
+ @parent.upload(src, current_directory(dst))
20
+ end
21
+
22
+ def download(src, dst)
23
+ @parent.download(current_directory(src), dst)
24
+ end
25
+
26
+ def within(directory, &block)
27
+ directory = current_directory(directory)
28
+
29
+ raise RuntimeError, directory unless test?(directory, '-d')
30
+
31
+ Task.new(self, directory).action &block
32
+ end
33
+
34
+ def action(&block)
35
+ instance_eval &block
36
+ end
37
+
38
+ def current_directory(directory = nil)
39
+ File.join(*([@parent&.current_directory, @directory, directory].compact))
40
+ end
41
+ end
42
+ end
@@ -1,3 +1,3 @@
1
1
  module PrepKit
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/prep_kit.rb CHANGED
@@ -6,5 +6,5 @@ module PrepKit
6
6
  class NotFoundError < StandardError; end
7
7
  end
8
8
 
9
- require_relative 'prep_kit/context'
10
- require_relative 'prep_kit/task'
9
+ require 'prep_kit/context'
10
+ require 'prep_kit/task'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prep_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - daisuko
@@ -63,12 +63,15 @@ files:
63
63
  - ".travis.yml"
64
64
  - CODE_OF_CONDUCT.md
65
65
  - Gemfile
66
+ - Gemfile.lock
66
67
  - LICENSE.txt
67
68
  - README.md
68
69
  - Rakefile
69
70
  - bin/console
70
71
  - bin/setup
71
72
  - lib/prep_kit.rb
73
+ - lib/prep_kit/context.rb
74
+ - lib/prep_kit/task.rb
72
75
  - lib/prep_kit/version.rb
73
76
  - prep_kit.gemspec
74
77
  homepage: https://github.com/daisuko/prep_kit