cjsonci 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7de1201678c4bcf5b483ea4ba8c646b4502a30ade56628da305809679a38745c
4
+ data.tar.gz: 9579f36f09b3ad720509c3059040ba4597c907a8d0077c9542ccf068af2d0434
5
+ SHA512:
6
+ metadata.gz: 5579117a08a420b89ae94b321c79b539ee6e31ef47d68c87b7267d7d37ee086f608508414edcdd9b67327f364fd31b93acc93c86844a825bd0d7a2d1c9ced165
7
+ data.tar.gz: d70758d03a7493f1d5041a4794fd05f5859b24f2571fec6809d9a2f9e98db8f5185e67e4256697533980d70c3547dff274e8b422bd6609bc85b73cc83b3c9916
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ cjsonci
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.5.1
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.0
5
+ before_install: gem install bundler -v 1.16.0
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in cjsonci.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cjsonci (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.3)
10
+ kommando (0.1.2)
11
+ rake (10.5.0)
12
+ rspec (3.8.0)
13
+ rspec-core (~> 3.8.0)
14
+ rspec-expectations (~> 3.8.0)
15
+ rspec-mocks (~> 3.8.0)
16
+ rspec-core (3.8.0)
17
+ rspec-support (~> 3.8.0)
18
+ rspec-expectations (3.8.1)
19
+ diff-lcs (>= 1.2.0, < 2.0)
20
+ rspec-support (~> 3.8.0)
21
+ rspec-mocks (3.8.0)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-support (3.8.0)
25
+
26
+ PLATFORMS
27
+ ruby
28
+
29
+ DEPENDENCIES
30
+ bundler (~> 1.16)
31
+ cjsonci!
32
+ kommando
33
+ rake (~> 10.0)
34
+ rspec (~> 3.0)
35
+
36
+ BUNDLED WITH
37
+ 1.16.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Matti Paksula
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # CJSONCI
2
+
3
+ ```
4
+ $ ruby e2e/servant.rb
5
+ {"eval": "1+1"}
6
+ {"type":"ok","result":2}
7
+ ```
8
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cjsonci"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/cjsonci.gemspec ADDED
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "cjsonci/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cjsonci"
8
+ spec.version = CJSONCI::VERSION
9
+ spec.authors = ["Matti Paksula"]
10
+ spec.email = ["matti.paksula@iki.fi"]
11
+
12
+ spec.summary = "Common JSON Command Interface"
13
+ spec.homepage = "https://github.com/matti/cjsonci"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "kommando"
27
+ end
data/e2e/client.rb ADDED
@@ -0,0 +1,9 @@
1
+ require_relative "../lib/cjsonci"
2
+
3
+ c = CJSONCI::Client.new "ruby e2e/servant.rb"
4
+ c.eval "a = 1"
5
+ c.eval "b = a + 1"
6
+
7
+ value = c.eval "b"
8
+ puts value["result"]
9
+ raise "err" unless value["result"] == 2
data/e2e/servant.rb ADDED
@@ -0,0 +1,3 @@
1
+ require_relative "../lib/cjsonci"
2
+
3
+ CJSONCI::Servant.run!
@@ -0,0 +1,40 @@
1
+ require "json"
2
+ require "open3"
3
+
4
+ module CJSONCI
5
+ class Client
6
+ def initialize(cmd)
7
+ @stdin, @stdout, @stderr, @wait_thr = Open3.popen3(cmd)
8
+ @queue = Queue.new
9
+
10
+ # consider something like https://github.com/kontena/kontena/blob/edb1d6c40e1ceb1b5aae88501d35cda525b64339/cli/lib/kontena/cli/helpers/exec_helper.rb#L38-L51
11
+ Thread.new do
12
+ @stdout.each_line do |line|
13
+ @queue.push JSON.parse(line)
14
+ end
15
+ end
16
+ end
17
+
18
+ def eval(code)
19
+ input = {
20
+ eval: code,
21
+ }
22
+ @stdin.puts input.to_json
23
+ result = nil
24
+ begin
25
+ result = @queue.pop
26
+ rescue Exception => ex
27
+ @stderr.each_line do |line|
28
+ puts line
29
+ end
30
+ exit 1
31
+ end
32
+
33
+ result
34
+ end
35
+
36
+ def close
37
+ @stdin.close
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,59 @@
1
+ require "json"
2
+
3
+ module CJSONCI
4
+ module Servant
5
+ def self.run!
6
+ loop do
7
+ obj = read_input
8
+ result = eval_input(obj)
9
+ puts format_message(result).to_json
10
+ end
11
+ end
12
+
13
+ private
14
+
15
+ def self.read_input
16
+ input = ""
17
+ obj = nil
18
+ loop do
19
+ line = STDIN.gets
20
+ exit 0 unless line
21
+ input << line
22
+
23
+ begin
24
+ obj = JSON.parse(input)
25
+ rescue
26
+ end
27
+
28
+ break if obj
29
+ end
30
+
31
+ obj
32
+ end
33
+
34
+ def self.eval_input(obj)
35
+ code = obj["eval"]
36
+ eval_result = nil
37
+ begin
38
+ eval_result = TOPLEVEL_BINDING.eval code.to_s
39
+ rescue Exception => ex
40
+ eval_result = ex
41
+ end
42
+ end
43
+
44
+ def self.format_message(result)
45
+ if result.is_a? Exception
46
+ {
47
+ type: "error",
48
+ class: result.class,
49
+ message: result,
50
+ }
51
+ else
52
+ {
53
+ type: "ok",
54
+ result: result,
55
+ }
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,3 @@
1
+ module CJSONCI
2
+ VERSION = "0.1.0"
3
+ end
data/lib/cjsonci.rb ADDED
@@ -0,0 +1,8 @@
1
+ $stdout.sync = true
2
+
3
+ require_relative "cjsonci/version"
4
+ require_relative "cjsonci/client"
5
+ require_relative "cjsonci/servant"
6
+
7
+ module CJSONCI
8
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cjsonci
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matti Paksula
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-08-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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.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.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: kommando
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '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'
69
+ description:
70
+ email:
71
+ - matti.paksula@iki.fi
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".ruby-gemset"
79
+ - ".ruby-version"
80
+ - ".travis.yml"
81
+ - Gemfile
82
+ - Gemfile.lock
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - cjsonci.gemspec
89
+ - e2e/client.rb
90
+ - e2e/servant.rb
91
+ - lib/cjsonci.rb
92
+ - lib/cjsonci/client.rb
93
+ - lib/cjsonci/servant.rb
94
+ - lib/cjsonci/version.rb
95
+ homepage: https://github.com/matti/cjsonci
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.7.6
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Common JSON Command Interface
119
+ test_files: []