zazu 0.0.1 → 0.0.2

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +20 -0
  3. data/lib/zazu.rb +24 -2
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 122bb6333e70968f87c722ed46057098565a07f0a93cb1ea5c09d82217477e7e
4
- data.tar.gz: a0b0493d24f96653457e9853a2fc87108efbd1c958963684451fa55f7878c571
3
+ metadata.gz: c368efff2b6adff8716c4b69d860b482b95a36b3d055124fdb3eac1218fc15db
4
+ data.tar.gz: 4ea392972f1b5590571e252454e5e137ac9d502e25800c24fe5385920c2d1dde
5
5
  SHA512:
6
- metadata.gz: 56e99ec2ef45f43e69cdf274c04af0bfb2f1bdee65e5101b8bf1e3976677eb13b85bc48fc842546d3a191f3fff15c35d2a1fddf19358f547610c65dca674326c
7
- data.tar.gz: 8b0346c3e0d00771a5a764fe5f90958af5318b07daf69e75d1f06431c663c7de6c2d521385a9042c19cd464fbd8ec5cb4487cc497696dfd48098d979376ff772
6
+ metadata.gz: 04cdb1d755be034d09991859f44ff335ce110ac7f59746299b2631aad46abd5fc84cfb105c2499af186b5b81522bfb550cd03c6fe476cfa3e53bd5c03644bb4d
7
+ data.tar.gz: c1d9acf87bf13b41f8417395ea41a1b37602afa3eb9479e55d41bbb9895102a66937e9fbfb5543f0320430111de0bba6f6914695489f934b9ae2f3a9b8ccd5bc
data/README.md CHANGED
@@ -1,2 +1,22 @@
1
+ [![Gem Version](https://badge.fury.io/rb/zazu.svg)](http://badge.fury.io/rb/zazu)
2
+
1
3
  # zazu
2
4
  Fetch tools and run them
5
+
6
+ Example:
7
+ ```ruby
8
+ zazu = Zazu.new 'my-script'
9
+ zazu.fetch url: 'https://example.com/my_script.sh'
10
+ zazu.run ['--environment', 'prod']
11
+ ```
12
+
13
+ To fetch os-dependent tools:
14
+ ```ruby
15
+ zazu = Zazu.new 'my-script'
16
+ zazu.fetch do |os, arch|
17
+ # os will be :linux, :mac, :windows
18
+ # arch will be 32 or 64
19
+ "https://example.com/my_script-#{os}_#{arch}-bit"
20
+ end
21
+ ```
22
+
data/lib/zazu.rb CHANGED
@@ -8,8 +8,16 @@ require 'thread'
8
8
  require 'tmpdir'
9
9
  require 'uri'
10
10
 
11
+ # Fetch tools and run them
12
+ #
13
+ # Example:
14
+ #
15
+ # zazu = Zazu.new 'my-script'
16
+ # zazu.fetch url: 'https://example.com/my_script.sh'
17
+ # zazu.run ['--environment', 'prod']
18
+ #
11
19
  class Zazu
12
- VERSION = '0.0.1'
20
+ VERSION = '0.0.2'
13
21
 
14
22
  class Error < Exception; end
15
23
  class DownloadError < Error; end
@@ -17,6 +25,11 @@ class Zazu
17
25
 
18
26
  attr_reader :name, :path
19
27
 
28
+ # Creates the Zazu instance. Create as many as you like.
29
+ #
30
+ # * +:name:+ - The name of the command
31
+ # * +:logger:+ - Default to STDERR, can be replaced with another, e.g. IO::NIL
32
+ # * +:level:+ - Log level for the logger
20
33
  def initialize(name, logger: Logger.new(STDERR), level: Logger::INFO)
21
34
  @name = name
22
35
  @path = File.join Dir.tmpdir, name + '-download'
@@ -24,6 +37,10 @@ class Zazu
24
37
  @logger.level = level
25
38
  end
26
39
 
40
+ # Download the tool, to the temp directory
41
+ # * +:url:+ - The URL to the tool--Optional, can specity the block instead
42
+ # * +:age:+ - Seconds old the downloaded copy can be before downloading again--Default is 3600
43
+ # * +:block:+ - Receives the OS (:linux, :mac, :windows) and the machine arch (32 or 64)--Should return the URL
27
44
  def fetch(url: nil, age: 60*60, &block)
28
45
  return false if File.exists?(path) && Time.now - File.stat(path).mtime < age
29
46
 
@@ -33,6 +50,11 @@ class Zazu
33
50
  download_file url
34
51
  end
35
52
 
53
+ # Run the downloaded tool with arguments
54
+ # * +:args:+ - An array of args for the command
55
+ # * +:show:+ - A regexp of output (STDOUT and STDERR) to include
56
+ # * +:hide:+ - A regexp of output (STDOUT and STDERR) to exclude
57
+ # * +:block:+ - If given, receies each output line, otherwise output is logged
36
58
  def run(args = [], show: //, hide: /^$/, &block)
37
59
  command = [path] + args
38
60
  @logger.debug "Running command #{command}".yellow
@@ -100,7 +122,7 @@ class Zazu
100
122
  when /darwin/i
101
123
  :mac
102
124
  when /windows/i
103
- :win
125
+ :windows
104
126
  end
105
127
  end
106
128
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zazu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Calhoun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-17 00:00:00.000000000 Z
11
+ date: 2019-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -57,5 +57,5 @@ requirements: []
57
57
  rubygems_version: 3.0.2
58
58
  signing_key:
59
59
  specification_version: 4
60
- summary: Download tools and run them
60
+ summary: Fetch tools and run them
61
61
  test_files: []