shortorder 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a945a1189ea397f0e2f6fbfae0f1466c0b8d56ec
4
+ data.tar.gz: 73611b62f011c2475c4b68a60ed6a56a93c6a3d2
5
+ SHA512:
6
+ metadata.gz: ed76dc40eb4ee5aa56b13f722eedf5cee4fd18fa7e5d20cad15c645cd4ef263a9b367119d9af4fde8da741b336df41d4d1472a9a74fadaad0964dec5644e8fca
7
+ data.tar.gz: 5aae992699f53edf21fd6e9591aaf70f3a0ee1eed85c6f31bf66a44dbd4630d6c56f92bb43cdea9779721ab0fe3df373d5a7c4da19c522f3efc8f6befac32ba5
@@ -0,0 +1,2 @@
1
+ # v0.0.1
2
+ * Initial alpha release
File without changes
data/LICENSE ADDED
File without changes
@@ -0,0 +1 @@
1
+ # Short Order
@@ -0,0 +1,24 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'shortorder'
4
+
5
+ Bogo::Cli::Setup.define do
6
+
7
+ on :v, :version, 'Print version' do
8
+ puts "shortorder - Short Order CLI tools and helpers - [Version: #{Shortorder::VERSION}]"
9
+ exit
10
+ end
11
+
12
+ command 'custom-service' do
13
+ description 'Generate custom service scaffold'
14
+
15
+ on :r, :root=, 'Root module namespace', :default => 'CustomShort'
16
+ on :c, :callback=, 'Callback class name', :default => 'Runner'
17
+ on :p, 'service-path=', 'Custom path to containing directory', :default => '.'
18
+
19
+ run do |opts, args|
20
+ Shortorder::Command::CustomService.new({:custom_service => opts.to_hash}, args).execute!
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,6 @@
1
+ require 'shortorder/version'
2
+ require 'bogo-cli'
3
+
4
+ module Shortorder
5
+ autoload :Command, 'shortorder/command'
6
+ end
@@ -0,0 +1,9 @@
1
+ require 'shortorder'
2
+
3
+ module Shortorder
4
+ class Command < Bogo::Cli::Command
5
+
6
+ autoload :CustomService, 'shortorder/command/custom_service'
7
+
8
+ end
9
+ end
@@ -0,0 +1,245 @@
1
+ require 'fileutils'
2
+ require 'shortorder'
3
+
4
+ module Shortorder
5
+ class Command
6
+
7
+ class CustomService < Command
8
+
9
+ attr_reader :root_name, :root_class
10
+ attr_reader :task_name, :task_class
11
+ attr_reader :callback_name, :callback_class
12
+ attr_reader :full_name, :full_class
13
+ attr_reader :service_path
14
+
15
+ # Generate custom service scaffold.
16
+ def execute!
17
+ unless(arguments.size == 1)
18
+ raise ArgumentError.new('Single argument name of service is required!')
19
+ end
20
+
21
+ @root_name = Bogo::Utility.snake(config[:root].tr('-.', '_'))
22
+ @root_class = Bogo::Utility.camel(root_name)
23
+ @task_name = Bogo::Utility.snake(arguments.first.tr('-.', '_'))
24
+ @task_class = Bogo::Utility.camel(task_name)
25
+ @callback_name = Bogo::Utility.snake(config[:callback].tr('-.', '_'))
26
+ @callback_class = Bogo::Utility.camel(callback_name)
27
+
28
+ @full_name = "#{root_name}-#{task_name}".tr('_', '-')
29
+ @full_class = "#{root_class}::#{task_class}"
30
+ @service_path = File.join(config[:service_path], full_name)
31
+
32
+ run_action 'Validating service directory' do
33
+ if(File.directory?(service_path))
34
+ ui.puts ui.color('path exists', :yellow)
35
+ ui.confirm 'Overwrite existing contents of service path'
36
+ ui.info 'Validating service directory... ', :nonewline
37
+ end
38
+ FileUtils.mkdir_p(service_path)
39
+ nil
40
+ end
41
+
42
+ run_action 'Generating service directory structure' do
43
+ FileUtils.mkdir_p(File.join(service_path, 'lib', full_name))
44
+ nil
45
+ end
46
+
47
+ run_action 'Writing service scaffolding files' do
48
+ write_gemspec!
49
+ write_version!
50
+ write_loader!
51
+ write_callback!
52
+ write_readme!
53
+ nil
54
+ end
55
+
56
+ run_action 'Writing Gemfile for local bundle' do
57
+ write_gemfile!
58
+ nil
59
+ end
60
+
61
+ run_action 'Writing service configuration file' do
62
+ write_config!
63
+ nil
64
+ end
65
+
66
+ ui.info "Created new custom service `#{ui.color(task_name, :green, :bold)}` at #{service_path}"
67
+ ui.puts " To get started, change directory to: #{ui.color(service_path, :bold)}"
68
+ ui.puts " Install the bundle: #{ui.color('bundle install', :bold)}"
69
+ ui.puts " Start the service: #{ui.color('bundle exec jackal -c config.json', :bold)}"
70
+ end
71
+
72
+ protected
73
+
74
+ # Write scaffold gemspec for new service
75
+ def write_gemspec!
76
+ File.open(File.join(service_path, "#{full_name}.gemspec"), 'w+') do |file|
77
+ file.puts <<-EOF
78
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
79
+ require '#{full_name}/version'
80
+ Gem::Specification.new do |s|
81
+ s.name = '#{full_name}'
82
+ s.version = #{full_class}::VERSION.version
83
+ s.summary = 'Custom Short Order Service'
84
+ s.author = 'CHANGE ME'
85
+ s.email = 'changeme@example.com'
86
+ s.homepage = 'https://example.com'
87
+ s.description = 'Custom Short Order Service: #{task_name}'
88
+ s.require_path = 'lib'
89
+ s.license = 'Apache 2.0'
90
+ s.add_runtime_dependency 'jackal', '~> 0.3.18'
91
+ s.add_runtime_dependency 'carnivore-http', '~> 0.2.8'
92
+ s.files = Dir['{lib}/**/**/*'] + %w(#{full_name}.gemspec)
93
+ end
94
+ EOF
95
+ end
96
+ end
97
+
98
+ # Write scaffold version for new service
99
+ def write_version!
100
+ File.open(File.join(service_path, 'lib', full_name, 'version.rb'), 'w+') do |file|
101
+ file.puts <<-EOF
102
+ module #{root_class}
103
+ module #{task_class}
104
+ # Current version
105
+ VERSION = Gem::Version.new('0.1.0')
106
+ end
107
+ end
108
+ EOF
109
+ end
110
+ end
111
+
112
+ # Write scaffold loader for new service
113
+ def write_loader!
114
+ File.open(File.join(service_path, 'lib', "#{full_name}.rb"), 'w+') do |file|
115
+ file.puts <<-EOF
116
+ require '#{full_name}/version'
117
+ require 'jackal'
118
+
119
+ module #{root_class}
120
+ module #{task_class}
121
+ autoload :#{callback_class}, '#{full_name}/#{callback_name}'
122
+ end
123
+ end
124
+ EOF
125
+ end
126
+ end
127
+
128
+ # Write scaffold callback for new service
129
+ def write_callback!
130
+ File.open(File.join(service_path, 'lib', full_name, "#{callback_name}.rb"), 'w+') do |file|
131
+ file.puts <<-EOF
132
+ require '#{full_name}'
133
+
134
+ module #{root_class}
135
+ module #{task_class}
136
+ class #{callback_class} < Jackal::Callback
137
+
138
+ # Perform any setup tasks required for this callback. This
139
+ # method is called after the callback is initialized and
140
+ # prior to any message processing.
141
+ def setup(*_)
142
+ end
143
+
144
+ # Determine if the received message is valid for this
145
+ # callback. If valid, the message will be processed.
146
+ #
147
+ # @param message [Carnivore::Message] received message
148
+ # @return [Truthy, Falsey]
149
+ # @note: Original scaffold generation always returns true
150
+ def valid?(message)
151
+ super do |payload|
152
+ true
153
+ end
154
+ end
155
+
156
+ # Perform a task based on the received message.
157
+ #
158
+ # @param message [Carnivore::Message] received message
159
+ # @return [Object, NilClass] returned value is not used
160
+ def execute(message)
161
+ failure_wrap(message) do |payload|
162
+ info 'Received new message from Short Order!'
163
+ info "Message payload contents:\\n\#{MultiJson.dump(payload, :pretty => true)}"
164
+ info 'Setting task as complete and notifying Short Order'
165
+ job_completed(:#{task_name}, payload, message)
166
+ end
167
+ end
168
+
169
+ end
170
+ end
171
+ end
172
+ EOF
173
+ end
174
+ end
175
+
176
+ # Write scaffold Gemfile for new service
177
+ def write_gemfile!
178
+ File.open(File.join(service_path, 'Gemfile'), 'w+') do |file|
179
+ file.puts <<-EOF
180
+ source 'https://rubygems.org'
181
+
182
+ gemspec
183
+ EOF
184
+ end
185
+ end
186
+
187
+ # Write scaffold readme file for new service
188
+ def write_readme!
189
+ File.open(File.join(service_path, 'README.md'), 'w+') do |file|
190
+ file.puts <<-EOF
191
+ # Custom Short Order Service: #{task_name}
192
+
193
+ Provide information about #{task_name} here.
194
+ EOF
195
+ end
196
+ end
197
+
198
+ # Write scaffold configuration file for new service
199
+ def write_config!
200
+ File.open(File.join(service_path, 'config.json'), 'w+') do |file|
201
+ file.puts MultiJson.dump(
202
+ Smash.new(
203
+ :jackal => {
204
+ :require => [
205
+ 'carnivore-http',
206
+ full_name
207
+ ]
208
+ },
209
+ root_name => {
210
+ task_name => {
211
+ :config => {
212
+ },
213
+ :sources => {
214
+ :input => {
215
+ :type => :http_paths,
216
+ :args => {
217
+ :port => 9090,
218
+ :path => "/#{task_name}",
219
+ :method => :post
220
+ }
221
+ },
222
+ :output => {
223
+ :type => :http,
224
+ :args => {
225
+ :method => :post,
226
+ :endpoint => 'https://api.d2o.io/v1/restore',
227
+ :auto_process => false,
228
+ :enable_processing => false
229
+ }
230
+ }
231
+ },
232
+ :callbacks => [
233
+ "#{full_class}::#{callback_class}"
234
+ ]
235
+ }
236
+ }
237
+ ),
238
+ :pretty => true
239
+ )
240
+ end
241
+ end
242
+
243
+ end
244
+ end
245
+ end
@@ -0,0 +1,4 @@
1
+ module Shortorder
2
+ # Current version
3
+ VERSION = Gem::Version.new('0.0.1')
4
+ end
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__)) + '/lib/'
2
+ require 'shortorder/version'
3
+ Gem::Specification.new do |s|
4
+ s.name = 'shortorder'
5
+ s.version = Shortorder::VERSION.version
6
+ s.summary = 'Short Order CLI'
7
+ s.author = 'Heavy Water'
8
+ s.email = 'support@shortorder.io'
9
+ s.homepage = 'https://github.com/shortorder/shortorder'
10
+ s.description = 'Short Order CLI tools and helpers'
11
+ s.require_path = 'lib'
12
+ s.license = 'Apache 2.0'
13
+ s.add_runtime_dependency 'bogo-cli', '~> 0.1'
14
+ s.files = Dir['{lib,bin}/**/**/*'] + %w(shortorder.gemspec README.md CHANGELOG.md CONTRIBUTING.md LICENSE)
15
+ s.executables << 'shortorder'
16
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shortorder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Heavy Water
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bogo-cli
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ description: Short Order CLI tools and helpers
28
+ email: support@shortorder.io
29
+ executables:
30
+ - shortorder
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CHANGELOG.md
35
+ - CONTRIBUTING.md
36
+ - LICENSE
37
+ - README.md
38
+ - bin/shortorder
39
+ - lib/shortorder.rb
40
+ - lib/shortorder/command.rb
41
+ - lib/shortorder/command/custom_service.rb
42
+ - lib/shortorder/version.rb
43
+ - shortorder.gemspec
44
+ homepage: https://github.com/shortorder/shortorder
45
+ licenses:
46
+ - Apache 2.0
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.2.2
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Short Order CLI
68
+ test_files: []
69
+ has_rdoc: