ddslbg 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Bjørn Arild Mæland
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Ddslbg
2
+
3
+ This library spawns a child process which communicates with the
4
+ [DDSL command line tool](https://github.com/mbknor/ddsl/blob/master/ddsl-cmdline-tool/).
5
+
6
+ Just a proof of concept.
7
+
8
+ ## Installation
9
+
10
+ ```ruby
11
+ gem install ddslbg
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```ruby
17
+ require 'ddslbg'
18
+
19
+ $ddsl = Ddslbg::Client.new
20
+
21
+ service = {
22
+ id: {environment: 'test', serviceType: 'http', name: 'cmd-tool', version: '0.1'},
23
+ sl: {url: 'http://localhost:4321/hi', quality: 1.0, lastUpdated: 1347398923243, ip: '127.0.0.1'}
24
+ }
25
+
26
+ $ddsl.up(service) # Register the service, uses ddsl serviceUp
27
+
28
+ $ddsl.available_services # List all available services, uses ddsl getAllAvailableServices
29
+
30
+ $ddsl.down(service) # Explicitly deregister the service, uses ddsl serviceDown
31
+ ```
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ desc 'Open an irb session preloaded with this library'
4
+ task :console do
5
+ sh 'irb -rubygems -I lib -r awesome_print -r ddslbg'
6
+ end
data/ddslbg.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ddslbg/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'ddslbg'
8
+ gem.version = Ddslbg::VERSION
9
+ gem.authors = ['Bjørn Arild Mæland']
10
+ gem.email = ['bjorn.maeland@gmail.com']
11
+ gem.description = 'This library spawns a child process which communicates with the DDSL command line tool'
12
+ gem.summary = 'Ruby client which wraps ddsl-cmdline-tool'
13
+ gem.homepage = 'https://github.com/bmaland/ddslbg'
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_development_dependency 'awesome_print'
21
+ end
@@ -0,0 +1,63 @@
1
+ module Ddslbg
2
+ class Client
3
+ BUNDLED_JAR_PATH = File.expand_path(
4
+ '../../../vendor/bin/ddsl-cmdline-tool_2.10-0.3.5-SNAPSHOT-one-jar.jar',
5
+ __FILE__)
6
+
7
+ attr_reader :options
8
+
9
+ def initialize(options={})
10
+ default_opts = {
11
+ java_cmd: 'java -jar',
12
+ jar_path: BUNDLED_JAR_PATH
13
+ }
14
+ @options = default_opts.merge(options)
15
+
16
+ connect!
17
+ end
18
+
19
+ def available_services
20
+ send('getAllAvailableServices')
21
+ end
22
+
23
+ def up(service)
24
+ send('serviceUp', service)
25
+ end
26
+
27
+ def down(service)
28
+ send('serviceDown', service)
29
+ end
30
+
31
+ # Send a raw command to DDSL.
32
+ #
33
+ # `data` can be a Ruby array or hash. It is converted to JSON before it is
34
+ # sent to DDSL.
35
+ def send(msg, data=nil)
36
+ cmd = msg
37
+ cmd += " #{data.to_json}" if data
38
+ @stdin.puts(cmd)
39
+ parse(process_line(@stdout.gets))
40
+ end
41
+
42
+ private
43
+
44
+ def connect!
45
+ cmd = [options[:java_cmd], options[:jar_path]].join(' ')
46
+ @stdin, @stdout, @stderr = Open3.popen3(cmd)
47
+
48
+ process_line(@stdout.gets)
49
+ end
50
+
51
+ def process_line(line='')
52
+ status, data = line.scan(/^([a-z]+) (.+)/).flatten
53
+ raise StandardError.new("[ddslbg] #{line}") unless status == 'ok'
54
+ data
55
+ end
56
+
57
+ def parse(str)
58
+ return true if str == 'true'
59
+ return false if str == 'false'
60
+ JSON.parse(str)
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ module Ddslbg
2
+ VERSION = "0.0.1"
3
+ end
data/lib/ddslbg.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'open3'
2
+ require 'json'
3
+
4
+ require 'ddslbg/version'
5
+ require 'ddslbg/client'
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ddslbg
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Bjørn Arild Mæland
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ prerelease: false
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ! '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ none: false
22
+ type: :development
23
+ name: awesome_print
24
+ requirement: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ! '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ none: false
30
+ description: This library spawns a child process which communicates with the DDSL
31
+ command line tool
32
+ email:
33
+ - bjorn.maeland@gmail.com
34
+ executables: []
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - .gitignore
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - ddslbg.gemspec
44
+ - lib/ddslbg.rb
45
+ - lib/ddslbg/client.rb
46
+ - lib/ddslbg/version.rb
47
+ - vendor/bin/ddsl-cmdline-tool_2.10-0.3.5-SNAPSHOT-one-jar.jar
48
+ homepage: https://github.com/bmaland/ddslbg
49
+ licenses: []
50
+ post_install_message:
51
+ rdoc_options: []
52
+ require_paths:
53
+ - lib
54
+ required_ruby_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ none: false
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ none: false
66
+ requirements: []
67
+ rubyforge_project:
68
+ rubygems_version: 1.8.25
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Ruby client which wraps ddsl-cmdline-tool
72
+ test_files: []