hivonic 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.envrc.example +1 -0
- data/.gitignore +14 -0
- data/.ruby-version.example +1 -0
- data/.travis.yml +5 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +11 -0
- data/Gemfile.lock +24 -0
- data/LICENSE +20 -0
- data/README.md +47 -0
- data/Rakefile.rb +11 -0
- data/bin/hivonic +63 -0
- data/hivonic.gemspec +30 -0
- data/lib/hivonic/commands.rb +210 -0
- data/lib/hivonic/common/string_helper.rb +79 -0
- data/lib/hivonic/version.rb +3 -0
- data/lib/hivonic.rb +10 -0
- data/test/test_helper.rb +4 -0
- data/test/unit/commands_test.rb +89 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ce1271a2a7e8a46a17c6df3e796918f76d7df93c
|
4
|
+
data.tar.gz: a87587af4fabfebedb2254f8827da4ad79432668
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c7c968719506310322513f21a56eecf824cdfee320f3ccb3462d68349232981e568cfdc7f46e8654654dffe7f84a14feece64fa44a445086426b429bf685013c
|
7
|
+
data.tar.gz: d60377e3ea9145876fc06d2f26fae7ee9961b897e415c36f3467710e370427371fd1196a8bf9b93d93849de28687b0ecf3e2fef49960324149eaf41cbcb606b7
|
data/.envrc.example
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
PATH_add bin
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.4
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
Hivonic Changelog
|
2
|
+
===
|
3
|
+
|
4
|
+
0.2.0
|
5
|
+
---
|
6
|
+
* Added ability to specify match group index for regexp time capture
|
7
|
+
* Tweaked Gemfile and hivonic.gemspec
|
8
|
+
* Added unit tests and example files
|
9
|
+
|
10
|
+
0.1.0
|
11
|
+
---
|
12
|
+
* Basic functionality for cleaning up temporary tables
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
coderay (1.1.0)
|
5
|
+
metaclass (0.0.4)
|
6
|
+
method_source (0.8.2)
|
7
|
+
mocha (1.1.0)
|
8
|
+
metaclass (~> 0.0.1)
|
9
|
+
pry (0.10.1)
|
10
|
+
coderay (~> 1.1.0)
|
11
|
+
method_source (~> 0.8.1)
|
12
|
+
slop (~> 3.4)
|
13
|
+
rake (10.4.2)
|
14
|
+
shoulda-context (1.2.1)
|
15
|
+
slop (3.6.0)
|
16
|
+
|
17
|
+
PLATFORMS
|
18
|
+
ruby
|
19
|
+
|
20
|
+
DEPENDENCIES
|
21
|
+
mocha (~> 1.1.0)
|
22
|
+
pry (~> 0.10.0)
|
23
|
+
rake (~> 10.4.0)
|
24
|
+
shoulda-context (~> 1.2.0)
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Will Drew
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
hivonic
|
2
|
+
========
|
3
|
+
|
4
|
+
Tonic oriented utilities for hive (Hive + Tonic => hivonic)
|
5
|
+
|
6
|
+
This tool requires tmp hive tables to include timestamp as part of the table name by convention.
|
7
|
+
|
8
|
+
### Status
|
9
|
+
[![Build Status](https://travis-ci.org/willdrew/hivonic.svg?branch=master)](https://travis-ci.org/willdrew/hivonic)
|
10
|
+
|
11
|
+
|
12
|
+
## Shell Environment Variables
|
13
|
+
- $HIVONIC_HIVE_OPTS
|
14
|
+
* Options passed to the hive client
|
15
|
+
* Defaults to '-S' # Silent
|
16
|
+
- $HIVONIC_REGEXP
|
17
|
+
* This is the regexp used to match tables and capture time from name
|
18
|
+
* Defaults to '\A(tmp|view)[a-z|_|0-9]+_(\d{14})\Z'
|
19
|
+
- $HIVONIC_TIME_FORMAT
|
20
|
+
* This is the time format used to parse the timestamp from the table name
|
21
|
+
* Defaults to '%Y%m%d%H%M%S'
|
22
|
+
- $HIVONIC_TIME_GROUP_INDEX
|
23
|
+
* Ability to specify match group index for regexp time capture
|
24
|
+
* Defaults to '2'
|
25
|
+
- $HIVONIC_TTL
|
26
|
+
* This is the Time-To-Live for Hive temporary tables
|
27
|
+
* Defaults to '86400' (24 hours)
|
28
|
+
|
29
|
+
|
30
|
+
## Hadpuils' Commands
|
31
|
+
- list __db__
|
32
|
+
* Lists all tmp hive tables that match regexp and are expired
|
33
|
+
- rm __db__ __table__
|
34
|
+
* Removes specified table from specified db
|
35
|
+
- cleanup __db__
|
36
|
+
* Cleans up (removes) all tmp hive tables that match regexp and are expired
|
37
|
+
|
38
|
+
|
39
|
+
### Example Usages
|
40
|
+
``` shell
|
41
|
+
hivonic list default
|
42
|
+
hivonic cleanup default
|
43
|
+
hivonic rm default sometimestamp_sometable
|
44
|
+
```
|
45
|
+
|
46
|
+
|
47
|
+
Credit [Ethan Rowe ](https://github.com/ethanrowe) for the original command handler technique in [hadupils](https://github.com/ethanrowe/hadupils).
|
data/Rakefile.rb
ADDED
data/bin/hivonic
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# vim: set filetype=ruby:
|
4
|
+
|
5
|
+
require 'gli'
|
6
|
+
require 'hivonic'
|
7
|
+
|
8
|
+
include GLI::App
|
9
|
+
include Hivonic::Commands
|
10
|
+
|
11
|
+
version Hivonic::VERSION
|
12
|
+
|
13
|
+
program_desc 'A simple hive utility application for cleaning up temporary tables'
|
14
|
+
|
15
|
+
# arg_name 'database'
|
16
|
+
|
17
|
+
hive_opts = ENV['HIVONIC_HIVE_OPTS'] || '-S' # -hiveconf hive.root.logger=DEBUG -S
|
18
|
+
regexp = ENV['HIVONIC_REGEXP'] || '\A(tmp|view)[a-z|_|0-9]+_(\d{14})\Z'
|
19
|
+
time_format = ENV['HIVONIC_TIME_FORMAT'] || '%Y%m%d%H%M%S'
|
20
|
+
time_group_index = ENV['HIVONIC_TIME_GROUP_INDEX'] || 2
|
21
|
+
ttl = ENV['HIVONIC_TTL'] || 86400
|
22
|
+
|
23
|
+
flag ['hive-opts'], :default_value => hive_opts
|
24
|
+
flag ['regexp'], :default_value => regexp
|
25
|
+
flag ['time-format'], :default_value => time_format
|
26
|
+
flag ['time-group-index'], :default_value => time_group_index
|
27
|
+
flag ['ttl'], :default_value => ttl
|
28
|
+
|
29
|
+
# switch [:d, 'debug']
|
30
|
+
# switch [:v, 'verbose']
|
31
|
+
switch [:n, 'dry-run']
|
32
|
+
|
33
|
+
def database_check!(args)
|
34
|
+
exit_now!('No database given!') if args[0].nil? || args[0].empty?
|
35
|
+
end
|
36
|
+
|
37
|
+
def table_check!(args)
|
38
|
+
exit_now!('No table given!') if args[1].nil? || args[1].empty?
|
39
|
+
end
|
40
|
+
|
41
|
+
command :list do |c|
|
42
|
+
c.action do |global_options, options, args|
|
43
|
+
database_check!(args)
|
44
|
+
Hivonic::Commands.run 'list_tables', global_options, args
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
command :rm do |c|
|
49
|
+
c.action do |global_options, options, args|
|
50
|
+
database_check!(args)
|
51
|
+
table_check!(args)
|
52
|
+
Hivonic::Commands.run 'drop_table', global_options, args
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
command :cleanup do |c|
|
57
|
+
c.action do |global_options, options, args|
|
58
|
+
database_check!(args)
|
59
|
+
Hivonic::Commands.run 'cleanup_tables', global_options, args
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
exit run(ARGV)
|
data/hivonic.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require File.expand_path('../lib/hivonic/version', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = 'hivonic'
|
7
|
+
gem.version = Hivonic::VERSION
|
8
|
+
gem.platform = Gem::Platform::RUBY
|
9
|
+
gem.authors = ['Will Drew']
|
10
|
+
gem.email = ['willdrew@gmail.com']
|
11
|
+
gem.summary = %q{Tonic oriented utilities for hive (Hive + Tonic => hivonic)}
|
12
|
+
gem.description = %q{Hivonic provides utilities for dealing with temporary hive tables}
|
13
|
+
gem.homepage = 'https://github.com/willdrew/hivonic'
|
14
|
+
|
15
|
+
gem.required_rubygems_version = '>= 1.3.6'
|
16
|
+
gem.required_ruby_version = ::Gem::Requirement.new('>= 1.9.3')
|
17
|
+
|
18
|
+
gem.add_dependency('gli', '~> 2.13.0')
|
19
|
+
gem.add_development_dependency('rake', '~> 10.4.0')
|
20
|
+
gem.add_development_dependency('bundler', '~> 1.7.0')
|
21
|
+
gem.add_development_dependency('pry', '~> 0.10.0')
|
22
|
+
gem.add_development_dependency('mocha', '~> 1.1.0')
|
23
|
+
gem.add_development_dependency('shoulda-context', '~> 1.2.0')
|
24
|
+
|
25
|
+
gem.files = `git ls-files`.split($\)
|
26
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
27
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
28
|
+
|
29
|
+
gem.require_paths = %w(lib)
|
30
|
+
end
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
using Hivonic::Common::StringHelper unless RUBY_VERSION < '2.0'
|
4
|
+
|
5
|
+
module Hivonic::Commands
|
6
|
+
def self.run(cmd, opts, args)
|
7
|
+
handler = handler_for cmd
|
8
|
+
output, exitstatus = handler.run opts, args
|
9
|
+
|
10
|
+
# Send Subcommand output to STDOUT
|
11
|
+
puts output
|
12
|
+
|
13
|
+
# Return exit status
|
14
|
+
exitstatus
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.normalize_cmd(cmd)
|
18
|
+
cmd.to_s.downcase
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.handler_for(cmd)
|
22
|
+
if @handlers
|
23
|
+
@handlers[normalize_cmd(cmd)]
|
24
|
+
else
|
25
|
+
raise 'Uh Oh!'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.register_handler_for(cmd, handler=nil)
|
30
|
+
normalized_cmd = normalize_cmd(cmd)
|
31
|
+
handler = Hivonic::Commands.const_get(normalized_cmd.classify) if handler.nil?
|
32
|
+
|
33
|
+
@handlers ||= {}
|
34
|
+
@handlers[normalized_cmd] = handler
|
35
|
+
end
|
36
|
+
|
37
|
+
class Subcommand
|
38
|
+
attr_reader :regexp
|
39
|
+
attr_reader :time_format
|
40
|
+
attr_reader :time_group_index
|
41
|
+
attr_reader :ttl
|
42
|
+
attr_reader :query
|
43
|
+
attr_reader :subcommand
|
44
|
+
attr_reader :dry_run
|
45
|
+
attr_reader :exitstatus
|
46
|
+
|
47
|
+
def initialize(opts, args)
|
48
|
+
@regexp = Regexp.new opts['regexp']
|
49
|
+
@time_format = opts['time-format']
|
50
|
+
@time_group_index = opts['time-group-index'].to_i
|
51
|
+
@ttl = opts['ttl'].to_i
|
52
|
+
@dry_run = opts['dry-run']
|
53
|
+
@exitstatus = 1
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.run(opts, args)
|
57
|
+
output, exitstatus = self.new(opts, args).run
|
58
|
+
return output, exitstatus
|
59
|
+
end
|
60
|
+
|
61
|
+
def subcommand
|
62
|
+
@subcommand = nil
|
63
|
+
end
|
64
|
+
|
65
|
+
def output(stdout)
|
66
|
+
stdout
|
67
|
+
end
|
68
|
+
|
69
|
+
def run
|
70
|
+
raise "subcommand can't be nil" if subcommand.nil?
|
71
|
+
|
72
|
+
if dry_run
|
73
|
+
stdout = "DRY RUN: Subcommand => #{subcommand}"
|
74
|
+
@exitstatus = 0
|
75
|
+
else
|
76
|
+
stdout = `#{subcommand}`
|
77
|
+
@exitstatus = $?.exitstatus
|
78
|
+
end
|
79
|
+
|
80
|
+
return output(stdout), self.exitstatus
|
81
|
+
end
|
82
|
+
|
83
|
+
def successful?
|
84
|
+
self.exitstatus == 0
|
85
|
+
end
|
86
|
+
|
87
|
+
def is_successful?(status)
|
88
|
+
status == 0
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
class HiveQueryCommand < Subcommand
|
93
|
+
attr_reader :hive_opts
|
94
|
+
attr_reader :db
|
95
|
+
|
96
|
+
def initialize(opts, args)
|
97
|
+
super
|
98
|
+
@hive_opts = opts['hive-opts']
|
99
|
+
@db = args[0]
|
100
|
+
end
|
101
|
+
|
102
|
+
def query
|
103
|
+
@query = nil
|
104
|
+
end
|
105
|
+
|
106
|
+
def subcommand
|
107
|
+
@subcommand = "hive #{self.hive_opts} -e \"#{self.query}\""
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
class ListTables < HiveQueryCommand
|
112
|
+
def is_expired?(time)
|
113
|
+
(Time.now.utc - self.ttl) > time
|
114
|
+
end
|
115
|
+
|
116
|
+
def is_table_expired?(table)
|
117
|
+
match = table.match self.regexp
|
118
|
+
|
119
|
+
if match.nil?
|
120
|
+
false
|
121
|
+
else
|
122
|
+
is_expired? Time.strptime(match[self.time_group_index], self.time_format)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def filter(stdout)
|
127
|
+
lines = stdout.split(/\n/)
|
128
|
+
|
129
|
+
lines.select do |line|
|
130
|
+
is_table_expired? line
|
131
|
+
end.join("\n")
|
132
|
+
end
|
133
|
+
|
134
|
+
def output(stdout)
|
135
|
+
if dry_run
|
136
|
+
super
|
137
|
+
else
|
138
|
+
filter(stdout)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def query
|
143
|
+
@query = "USE #{self.db}; SHOW TABLES;"
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
register_handler_for :list_tables
|
148
|
+
|
149
|
+
class DropTable < HiveQueryCommand
|
150
|
+
attr_reader :table
|
151
|
+
|
152
|
+
def initialize(opts, args)
|
153
|
+
super
|
154
|
+
@table = args[1]
|
155
|
+
end
|
156
|
+
|
157
|
+
def query
|
158
|
+
@query = "DROP TABLE '#{self.db}.#{self.table}';"
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
register_handler_for :drop_table
|
163
|
+
|
164
|
+
class CleanupTables < HiveQueryCommand
|
165
|
+
def list_tables
|
166
|
+
opts = {}
|
167
|
+
opts['regexp'] = self.regexp
|
168
|
+
opts['time-format'] = self.time_format
|
169
|
+
opts['time-group-index'] = self.time_group_index
|
170
|
+
opts['ttl'] = self.ttl
|
171
|
+
opts['hive-opts'] = self.hive_opts
|
172
|
+
|
173
|
+
output, status = ListTables.run opts, [self.db]
|
174
|
+
raise 'Uh oh!' unless is_successful? status
|
175
|
+
output.split(/\n/)
|
176
|
+
end
|
177
|
+
|
178
|
+
def filter(tables)
|
179
|
+
tables.select do |table|
|
180
|
+
is_table_expired? table
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def build_query
|
185
|
+
tables = list_tables
|
186
|
+
|
187
|
+
tables.map do |table|
|
188
|
+
opts = {}
|
189
|
+
opts['regexp'] = self.regexp
|
190
|
+
|
191
|
+
DropTable.new(opts, [self.db, table]).query
|
192
|
+
end.join(' ')
|
193
|
+
end
|
194
|
+
|
195
|
+
def query
|
196
|
+
@query = build_query
|
197
|
+
end
|
198
|
+
|
199
|
+
def subcommand
|
200
|
+
if self.query.nil? || self.query.empty?
|
201
|
+
puts 'Nothing to cleanup!'
|
202
|
+
Kernel.exit! 0
|
203
|
+
else
|
204
|
+
super
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
register_handler_for :cleanup_tables
|
210
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
if RUBY_VERSION < '2.0'
|
2
|
+
module Hivonic
|
3
|
+
module Common
|
4
|
+
module StringHelper
|
5
|
+
def randcase
|
6
|
+
dup.split('').map do |char|
|
7
|
+
if rand(1..10) > 5
|
8
|
+
char.upcase
|
9
|
+
else
|
10
|
+
char.downcase
|
11
|
+
end
|
12
|
+
end.join
|
13
|
+
end
|
14
|
+
|
15
|
+
def classify
|
16
|
+
self.split('_').collect(&:capitalize).join
|
17
|
+
end
|
18
|
+
|
19
|
+
def underscore
|
20
|
+
self.gsub(/::/, '/').
|
21
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
22
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
23
|
+
tr("-", "_").
|
24
|
+
downcase
|
25
|
+
end
|
26
|
+
|
27
|
+
def titleize
|
28
|
+
self.gsub(/\b('?[a-z])/) { $1.capitalize }
|
29
|
+
end
|
30
|
+
|
31
|
+
def titleize_words
|
32
|
+
self.gsub(/\w+/) { |s| s.capitalize }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class String
|
39
|
+
include Hivonic::Common::StringHelper
|
40
|
+
end
|
41
|
+
else
|
42
|
+
module Hivonic
|
43
|
+
module Common
|
44
|
+
module StringHelper
|
45
|
+
refine ::String do
|
46
|
+
def randcase
|
47
|
+
dup.split('').map do |char|
|
48
|
+
if rand(1..10) > 5
|
49
|
+
char.upcase
|
50
|
+
else
|
51
|
+
char.downcase
|
52
|
+
end
|
53
|
+
end.join
|
54
|
+
end
|
55
|
+
|
56
|
+
def classify
|
57
|
+
self.split('_').collect(&:capitalize).join
|
58
|
+
end
|
59
|
+
|
60
|
+
def underscore
|
61
|
+
self.gsub(/::/, '/').
|
62
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
63
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
64
|
+
tr("-", "_").
|
65
|
+
downcase
|
66
|
+
end
|
67
|
+
|
68
|
+
def titleize
|
69
|
+
self.gsub(/\b('?[a-z])/) { $1.capitalize }
|
70
|
+
end
|
71
|
+
|
72
|
+
def titleize_words
|
73
|
+
self.gsub(/\w+/) { |s| s.capitalize }
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
data/lib/hivonic.rb
ADDED
data/test/test_helper.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
using Hivonic::Common::StringHelper unless RUBY_VERSION < '2.0'
|
2
|
+
|
3
|
+
class Hivonic::CommandsTest < Test::Unit::TestCase
|
4
|
+
context Hivonic::Commands do
|
5
|
+
context 'run singleton method' do
|
6
|
+
should 'pass opts and args to #run method of the handler' do
|
7
|
+
Hivonic::Commands.expects(:handler_for).with(cmd = mock()).returns(handler = mock())
|
8
|
+
handler.expects(:run).with(opts = mock(), args = mock()).returns([output = mock(), exitstatus = mock()])
|
9
|
+
assert_equal exitstatus, Hivonic::Commands.run(cmd, opts, args)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context 'list tables' do
|
15
|
+
setup do
|
16
|
+
@klass = Hivonic::Commands::ListTables
|
17
|
+
end
|
18
|
+
|
19
|
+
should 'register with :list_tables' do
|
20
|
+
handlers = [:list_tables]
|
21
|
+
handlers.each do |handler|
|
22
|
+
Hivonic::Commands.register_handler_for handler
|
23
|
+
end
|
24
|
+
run_handler_assertions_for handlers
|
25
|
+
end
|
26
|
+
|
27
|
+
should 'have a #run singleton method that dispatches to an instance #run' do
|
28
|
+
opts = mock()
|
29
|
+
args = mock()
|
30
|
+
@klass.expects(:new).with(opts, args).returns(instance = mock())
|
31
|
+
instance.expects(:run).with.returns([output = mock(), exitstatus = mock()])
|
32
|
+
assert_equal [output, exitstatus], @klass.run(opts, args)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'drop table' do
|
37
|
+
setup do
|
38
|
+
@klass = Hivonic::Commands::DropTable
|
39
|
+
end
|
40
|
+
|
41
|
+
should 'register with :drop_table' do
|
42
|
+
handlers = [:drop_table]
|
43
|
+
handlers.each do |handler|
|
44
|
+
Hivonic::Commands.register_handler_for handler
|
45
|
+
end
|
46
|
+
run_handler_assertions_for handlers
|
47
|
+
end
|
48
|
+
|
49
|
+
should 'have a #run singleton method that dispatches to an instance #run' do
|
50
|
+
opts = mock()
|
51
|
+
args = mock()
|
52
|
+
@klass.expects(:new).with(opts, args).returns(instance = mock())
|
53
|
+
instance.expects(:run).with.returns([output = mock(), exitstatus = mock()])
|
54
|
+
assert_equal [output, exitstatus], @klass.run(opts, args)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context 'cleanup tables' do
|
59
|
+
setup do
|
60
|
+
@klass = Hivonic::Commands::CleanupTables
|
61
|
+
end
|
62
|
+
|
63
|
+
should 'register with :cleanup_tables' do
|
64
|
+
handlers = [:cleanup_tables]
|
65
|
+
handlers.each do |handler|
|
66
|
+
Hivonic::Commands.register_handler_for handler
|
67
|
+
end
|
68
|
+
run_handler_assertions_for handlers
|
69
|
+
end
|
70
|
+
|
71
|
+
should 'have a #run singleton method that dispatches to an instance #run' do
|
72
|
+
opts = mock()
|
73
|
+
args = mock()
|
74
|
+
@klass.expects(:new).with(opts, args).returns(instance = mock())
|
75
|
+
instance.expects(:run).with.returns([output = mock(), exitstatus = mock()])
|
76
|
+
assert_equal [output, exitstatus], @klass.run(opts, args)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def run_handler_assertions_for(handlers)
|
81
|
+
handlers.each do |handler|
|
82
|
+
handler = handler.to_s.downcase
|
83
|
+
assert_same @klass, Hivonic::Commands.handler_for(handler.to_sym)
|
84
|
+
assert_same @klass, Hivonic::Commands.handler_for(handler.randcase.to_sym)
|
85
|
+
assert_same @klass, Hivonic::Commands.handler_for(handler)
|
86
|
+
assert_same @klass, Hivonic::Commands.handler_for(handler.randcase)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hivonic
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Will Drew
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gli
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.13.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.13.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 10.4.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 10.4.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.7.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.7.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.10.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.10.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: mocha
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.1.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.1.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: shoulda-context
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.2.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.2.0
|
97
|
+
description: Hivonic provides utilities for dealing with temporary hive tables
|
98
|
+
email:
|
99
|
+
- willdrew@gmail.com
|
100
|
+
executables:
|
101
|
+
- hivonic
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".envrc.example"
|
106
|
+
- ".gitignore"
|
107
|
+
- ".ruby-version.example"
|
108
|
+
- ".travis.yml"
|
109
|
+
- CHANGELOG.md
|
110
|
+
- Gemfile
|
111
|
+
- Gemfile.lock
|
112
|
+
- LICENSE
|
113
|
+
- README.md
|
114
|
+
- Rakefile.rb
|
115
|
+
- bin/hivonic
|
116
|
+
- hivonic.gemspec
|
117
|
+
- lib/hivonic.rb
|
118
|
+
- lib/hivonic/commands.rb
|
119
|
+
- lib/hivonic/common/string_helper.rb
|
120
|
+
- lib/hivonic/version.rb
|
121
|
+
- test/test_helper.rb
|
122
|
+
- test/unit/commands_test.rb
|
123
|
+
homepage: https://github.com/willdrew/hivonic
|
124
|
+
licenses: []
|
125
|
+
metadata: {}
|
126
|
+
post_install_message:
|
127
|
+
rdoc_options: []
|
128
|
+
require_paths:
|
129
|
+
- lib
|
130
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: 1.9.3
|
135
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: 1.3.6
|
140
|
+
requirements: []
|
141
|
+
rubyforge_project:
|
142
|
+
rubygems_version: 2.2.2
|
143
|
+
signing_key:
|
144
|
+
specification_version: 4
|
145
|
+
summary: Tonic oriented utilities for hive (Hive + Tonic => hivonic)
|
146
|
+
test_files:
|
147
|
+
- test/test_helper.rb
|
148
|
+
- test/unit/commands_test.rb
|