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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 64a0586d51ae239c6480def393a0077ca10d3150
4
- data.tar.gz: 792db9e3058eb0d553b1e8ca3be953d28e0c41c9
3
+ metadata.gz: c4dde16790533cfc4b0c7eb7c3bf5f05b86adcac
4
+ data.tar.gz: 0eb085453afbd3e1461f66e416d4eea1c3eaf2fb
5
5
  SHA512:
6
- metadata.gz: 5560dfa3106ea0286c21583f921e2dc295b9afa799ce1474a8922b60d22f903c3f66c27b2c7c29d5e14a5de9a584ff46abbf4d4b22129242b96867ebd2c32fc8
7
- data.tar.gz: bc8e20a5e4ef4b393ed9ab6af824152eb6cef78e7dbedc31bc024f17abe95f18bac5e99fb9813d4c0a31f9b113956ff049b7598b3e93915e5dac8ab3bc9d3491
6
+ metadata.gz: 9558baf799866d0ea896c6dede845ab2f85401858ce7b953471cf00d64a4b3fb5afe86729567333b115d02430f717450b9aa1d05870a93297b062a3794ac4380
7
+ data.tar.gz: fd872243d8402203218b36074bffa2c8a48e50984707fcfcb170b46aae04eee16a95a568d29c953a70954ac5b12fe9ec66704172166ec4900b8182434727878d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 0.2.0
2
+
3
+ * Adds support for subcommands
4
+ * Adds a new parent class, `Cog::AggregateCommand`
5
+ * Adds a new parent class, `Cog::SubCommand`
6
+
1
7
  ## 0.1.15
2
8
 
3
9
  * Adds a `cogrb` binary that wraps some helper tasks in `lib/tasks/cog.rake`:
@@ -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
@@ -1,4 +1,8 @@
1
1
  class Cog
2
2
  class Error < RuntimeError
3
3
  end
4
+ class Abort < RuntimeError
5
+ end
6
+ class Stop < RuntimeError
7
+ end
4
8
  end
@@ -0,0 +1,16 @@
1
+ class Cog
2
+ class SubCommand
3
+
4
+ def initialize(request = nil)
5
+ @request = request
6
+ end
7
+
8
+ private
9
+
10
+ def request
11
+ @request
12
+ end
13
+
14
+ end
15
+ end
16
+
data/lib/cog/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Cog
2
- VERSION = "0.1.15"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.15
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-19 00:00:00.000000000 Z
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.4.5.1
97
+ rubygems_version: 2.5.1
96
98
  signing_key:
97
99
  specification_version: 4
98
100
  summary: Cog command helper library