utilitybelt 1.0.0.pre.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 +7 -0
- data/README.md +72 -0
- data/utilitybelt.rb +79 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4b5cc04781a7d68b4e38fb5f60a4cb0c64844e5c
|
4
|
+
data.tar.gz: caa8b8fe2210d27d18371dd3737fc9fa22f52451
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 968129f7a050d9e8e955a7c47fe26b7c8f49f80283a17b1f7e0aeabf2b5140d6504ca9c42a38d6419d76bbe65c3ae16cf8d7c4a52e97c433b4bdc3fe3c014904
|
7
|
+
data.tar.gz: c1a5d6eec742b2ce834930a0340a40d4836c009bfa34a4d1fb8e56ec251ce3187fe06f2c8078b3c3e188686c78544d035f749ba1214e051425538d9113b5c473
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
Utility Belt
|
2
|
+
============
|
3
|
+
|
4
|
+
My Ruby Utilities
|
5
|
+
|
6
|
+
## Install
|
7
|
+
|
8
|
+
```bash
|
9
|
+
gem install utilitybelt
|
10
|
+
```
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
### `UtilityBelt.mkdir(*path)`
|
15
|
+
|
16
|
+
> Wrapper for `FileUtils.mkdir`, which accepts path as argements to be joined and
|
17
|
+
> `noop`s if directory exists.
|
18
|
+
|
19
|
+
### `UtilityBelt.touch(*path)`
|
20
|
+
|
21
|
+
> Wrapper for `FileUtils.touch`, which accepts path as argements to be joined and
|
22
|
+
> set's file perms to `0644`.
|
23
|
+
|
24
|
+
### `UtilityBelt.save(path, body, bin=false)`
|
25
|
+
|
26
|
+
> Save `body` in `path`, optionally as binary data via `bin=true`.
|
27
|
+
|
28
|
+
### `UtilityBelt.exec(*command)`
|
29
|
+
|
30
|
+
> Run command as joined argements. Returns a `Struct`;
|
31
|
+
>
|
32
|
+
> ```
|
33
|
+
> #<struct stdout="STDOUT", stderr="STDERR", status=0>
|
34
|
+
> ```
|
35
|
+
|
36
|
+
### `UtilityBelt.encrypt!(source, destination, recipient)`
|
37
|
+
|
38
|
+
> GPG encrypts a `source` to a `destination`. Returns `destination`
|
39
|
+
|
40
|
+
### `UtilityBelt.decrypt(source, recipient)`
|
41
|
+
|
42
|
+
> GPG decrypts a `source`. Returns decrypted string.
|
43
|
+
|
44
|
+
### `UtilityBelt.decrypt!(source, destination, recipient)`
|
45
|
+
|
46
|
+
> GPG decrypts a `source` to a `destination`. Returns `destination`.
|
47
|
+
|
48
|
+
### `UtilityBelt::NullLogger`
|
49
|
+
|
50
|
+
> A noop logger.
|
51
|
+
>
|
52
|
+
> E.g.:
|
53
|
+
>
|
54
|
+
> ```ruby
|
55
|
+
> Something.new(:logger => UtilityBelt::NullLogger.new)
|
56
|
+
> ```
|
57
|
+
|
58
|
+
### Stay tuned, more to come.
|
59
|
+
|
60
|
+
## Development
|
61
|
+
|
62
|
+
Fork, clone and...
|
63
|
+
|
64
|
+
```bash
|
65
|
+
cd ruby-utilitybelt
|
66
|
+
bundle install --path .bundle
|
67
|
+
bundle exec rake test
|
68
|
+
|
69
|
+
# Or to test GPG stuff
|
70
|
+
# GPG_ID=<gpg email> bundle exec rake test
|
71
|
+
```
|
72
|
+
|
data/utilitybelt.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'omnistruct'
|
4
|
+
require 'open3'
|
5
|
+
|
6
|
+
module UtilityBelt
|
7
|
+
def self.mkdir *path
|
8
|
+
path = File.join(path)
|
9
|
+
FileUtils.mkdir(path, :mode => 0755) unless File.directory?(path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.touch *path
|
13
|
+
path = File.join(path)
|
14
|
+
FileUtils.touch(path)
|
15
|
+
File.chmod(0644, path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.save name, body, bin=false
|
19
|
+
flags = 'w'
|
20
|
+
flags += '+b' if bin
|
21
|
+
|
22
|
+
File.open(name, flags) { |f| f << body }
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.exec *cmd
|
26
|
+
cmd = cmd.join(" ")
|
27
|
+
|
28
|
+
stdout, stderr, status = Open3.capture3(cmd)
|
29
|
+
|
30
|
+
return {
|
31
|
+
:stdout => stdout,
|
32
|
+
:stderr => stderr,
|
33
|
+
:status => status
|
34
|
+
}.to_struct(:struct)
|
35
|
+
|
36
|
+
rescue Exception => e
|
37
|
+
return { :stdout => "", :stderr => e.message, :status => 1 }.to_struct
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.encrypt! src, dest, rec
|
41
|
+
cmd = [ "gpg --recipient", rec, "--batch --no-tty --yes",
|
42
|
+
"--output", dest, "--encrypt", src ]
|
43
|
+
|
44
|
+
res = exec(*cmd)
|
45
|
+
|
46
|
+
unless res.status == 0
|
47
|
+
raise res.stderr unless res.stderr.empty?
|
48
|
+
raise "GPG Encryption failed and I don't know why."
|
49
|
+
end
|
50
|
+
|
51
|
+
dest
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.decrypt src, rec
|
55
|
+
cmd = [ "gpg --decrypt --no-tty --recipient", rec, src ]
|
56
|
+
res = exec(*cmd)
|
57
|
+
|
58
|
+
unless res.status == 0
|
59
|
+
raise res.stderr unless res.stderr.empty?
|
60
|
+
raise "GPG Encryption failed and I don't know why."
|
61
|
+
end
|
62
|
+
|
63
|
+
res.stdout
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.decrypt_to src, dest, rec
|
67
|
+
res = self.decrypt(src, rec)
|
68
|
+
save(dest, res)
|
69
|
+
dest
|
70
|
+
end
|
71
|
+
|
72
|
+
class NullLogger < ::Logger
|
73
|
+
def initialize(*args)
|
74
|
+
end
|
75
|
+
|
76
|
+
def add(*args, &block)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: utilitybelt
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.pre.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joshua Mervine
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: omnistruct
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.4'
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 5.4.3
|
37
|
+
type: :development
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - "~>"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '5.4'
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 5.4.3
|
47
|
+
description: My Ruby Utility Belt -- Not really intended for general use, but you're
|
48
|
+
welcome to it.
|
49
|
+
email:
|
50
|
+
- joshua@mervine.net
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- README.md
|
56
|
+
- utilitybelt.rb
|
57
|
+
homepage: https://github.com/jmervine/ruby-utilitybelt
|
58
|
+
licenses:
|
59
|
+
- n/a
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- "."
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.3.1
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.2.2
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: My Ruby Utility Belt
|
81
|
+
test_files: []
|