cog-rb 0.1.15 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/cog/aggregate_command.rb +57 -0
- data/lib/cog/bundle.rb +11 -0
- data/lib/cog/exceptions.rb +4 -0
- data/lib/cog/subcommand.rb +16 -0
- data/lib/cog/version.rb +1 -1
- data/lib/cog.rb +2 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4dde16790533cfc4b0c7eb7c3bf5f05b86adcac
|
4
|
+
data.tar.gz: 0eb085453afbd3e1461f66e416d4eea1c3eaf2fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9558baf799866d0ea896c6dede845ab2f85401858ce7b953471cf00d64a4b3fb5afe86729567333b115d02430f717450b9aa1d05870a93297b062a3794ac4380
|
7
|
+
data.tar.gz: fd872243d8402203218b36074bffa2c8a48e50984707fcfcb170b46aae04eee16a95a568d29c953a70954ac5b12fe9ec66704172166ec4900b8182434727878d
|
data/CHANGELOG.md
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'cog/exceptions'
|
2
|
+
|
3
|
+
class Cog
|
4
|
+
class AggregateCommand < Cog::Command
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
subcommands = self.class.const_get("SUBCOMMANDS")
|
8
|
+
subcommand = request.args.shift
|
9
|
+
|
10
|
+
require_subcommand!(subcommand, subcommands)
|
11
|
+
|
12
|
+
load_subcommands(subcommands)
|
13
|
+
|
14
|
+
@subcommand_class = create_subcommand_class(subcommand)
|
15
|
+
end
|
16
|
+
|
17
|
+
def run_command
|
18
|
+
response.content = subcommand().run_command
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def subcommand
|
24
|
+
@subcommand_inst ||= @subcommand_class.new(request)
|
25
|
+
end
|
26
|
+
|
27
|
+
def load_subcommands(subcommands)
|
28
|
+
subcommands.each do |sc|
|
29
|
+
require File.join(File.dirname($0), 'lib', 'cog_cmd', ENV['COG_BUNDLE'], ENV['COG_COMMAND'], sc)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_subcommand_class(subcommand)
|
34
|
+
subcommand_class = subcommand.gsub(/(\A|_)([a-z])/) { $2.upcase }
|
35
|
+
self.class.const_get(subcommand_class)
|
36
|
+
end
|
37
|
+
|
38
|
+
def require_subcommand!(subcommand, subcommands, exception = Cog::Abort)
|
39
|
+
unless subcommand
|
40
|
+
raise exception, missing_subcommand_msg(subcommands)
|
41
|
+
end
|
42
|
+
|
43
|
+
unless subcommands.include?(subcommand)
|
44
|
+
raise exception, unknown_subcommand_msg(subcommand, subcommands)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def missing_subcommand_msg(subcommands)
|
49
|
+
"Missing subcommand. Please specify one of '#{subcommands.join(', ')}'"
|
50
|
+
end
|
51
|
+
|
52
|
+
def unknown_subcommand_msg(subcommand, subcommands)
|
53
|
+
"Unknown subcommand '#{subcommand}'. Please specify one of '#{subcommands.join(', ')}'"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
data/lib/cog/bundle.rb
CHANGED
@@ -35,6 +35,17 @@ class Cog
|
|
35
35
|
|
36
36
|
target = @module.const_get(command_class).new
|
37
37
|
target.execute
|
38
|
+
# Abort will end command execution and abort the pipeline
|
39
|
+
rescue Cog::Abort => msg
|
40
|
+
response = Cog::Response.new
|
41
|
+
response['body'] = msg
|
42
|
+
response.abort
|
43
|
+
response.send
|
44
|
+
# Stop will end command execution but the pipeline will continue
|
45
|
+
rescue Cog::Stop => msg
|
46
|
+
response = Cog::Response.new
|
47
|
+
response['body'] = msg
|
48
|
+
response.send
|
38
49
|
end
|
39
50
|
end
|
40
51
|
end
|
data/lib/cog/exceptions.rb
CHANGED
data/lib/cog/version.rb
CHANGED
data/lib/cog.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
require_relative 'cog/bundle'
|
3
3
|
require_relative 'cog/config'
|
4
4
|
require_relative 'cog/command'
|
5
|
+
require_relative 'cog/subcommand'
|
6
|
+
require_relative 'cog/aggregate_command'
|
5
7
|
require_relative 'cog/request'
|
6
8
|
require_relative 'cog/response'
|
7
9
|
require_relative 'cog/version'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cog-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Imbriaco
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -59,6 +59,7 @@ files:
|
|
59
59
|
- bin/setup
|
60
60
|
- cog-rb.gemspec
|
61
61
|
- lib/cog.rb
|
62
|
+
- lib/cog/aggregate_command.rb
|
62
63
|
- lib/cog/bundle.rb
|
63
64
|
- lib/cog/command.rb
|
64
65
|
- lib/cog/config.rb
|
@@ -68,6 +69,7 @@ files:
|
|
68
69
|
- lib/cog/service.rb
|
69
70
|
- lib/cog/services/memory.rb
|
70
71
|
- lib/cog/services/metadata.rb
|
72
|
+
- lib/cog/subcommand.rb
|
71
73
|
- lib/cog/version.rb
|
72
74
|
- lib/rspec/cog.rb
|
73
75
|
- lib/rspec/cog/matchers.rb
|
@@ -92,7 +94,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
92
94
|
version: '0'
|
93
95
|
requirements: []
|
94
96
|
rubyforge_project:
|
95
|
-
rubygems_version: 2.
|
97
|
+
rubygems_version: 2.5.1
|
96
98
|
signing_key:
|
97
99
|
specification_version: 4
|
98
100
|
summary: Cog command helper library
|