oskie_rpc 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +38 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/lib/oskie_rpc/exceptions.rb +5 -0
- data/lib/oskie_rpc/message.rb +23 -0
- data/lib/oskie_rpc/processor.rb +61 -0
- data/lib/oskie_rpc/version.rb +3 -0
- data/lib/oskie_rpc.rb +12 -0
- data/oskie_rpc.gemspec +25 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 83c95d50dce23208e4a87cd0fdc01b8e7e02cb3c
|
4
|
+
data.tar.gz: e0b414711d5ab9b51479c149c6bd60e20ce5f5ea
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fca7464ec46d3c3fe859684b1e8deb0e78cb6db969b155cb346d545fff2eb707f2e1385a921bf9efc08b6049013bf389249efa491bf1bd156008f28f27ba86d9
|
7
|
+
data.tar.gz: eb23f34873330d8f7fb78f5e3d327cab75fb59242d3bfd96bd1c0d4a0c0fb5abf636b0b42864041985c6e6c26d23c64e89def2df977391ee16b0e2a72ff8399e
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Chad Remesch
|
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,38 @@
|
|
1
|
+
# Oskie RPC [](https://travis-ci.org/chadrem/oskie_rpc)
|
2
|
+
|
3
|
+
Oskie RPC is an extremely simple and modular RPC library for Ruby.
|
4
|
+
Design goals include:
|
5
|
+
|
6
|
+
- Transport independent so no dependencies on TCP/IP, IO, or any other classes (it simply takes input and gives back output through callbacks).
|
7
|
+
- Modular design using the [Filter Chain](https://github.com/chadrem/filter_chain) gem so that the protocol can be modified if you so desire.
|
8
|
+
- Supports both messages and requests (requests can be replied to, messages can't).
|
9
|
+
- Very simple binary protocol with data encoded in JSON.
|
10
|
+
- Thread safe.
|
11
|
+
- Easy to port to other languages.
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
gem 'oskie_rpc'
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install oskie_rpc
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Coming soon.
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/chadrem/oskie_rpc.
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
38
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "oskie_rpc"
|
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
|
data/bin/setup
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
module OskieRpc
|
2
|
+
class Message
|
3
|
+
attr_reader :command
|
4
|
+
attr_reader :uuid
|
5
|
+
attr_reader :data
|
6
|
+
attr_reader :processor
|
7
|
+
|
8
|
+
def initialize(command, opts = {})
|
9
|
+
@command = command
|
10
|
+
@uuid = opts[:uuid] || SecureRandom.uuid
|
11
|
+
@data = opts[:data]
|
12
|
+
@parser = opts[:processor]
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_hash
|
16
|
+
{
|
17
|
+
:command => @command,
|
18
|
+
:uuid => @uuid,
|
19
|
+
:data => @data
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module OskieRpc
|
2
|
+
class Processor
|
3
|
+
def initialize(opts = {}, &block)
|
4
|
+
@opts = opts
|
5
|
+
@lock = Mutex.new
|
6
|
+
@input_chain = create_input_chain
|
7
|
+
@output_chain = create_output_chain
|
8
|
+
@callbacks = {}
|
9
|
+
@state = :initializing
|
10
|
+
block.call(self) if block
|
11
|
+
raise MissingCallbackError, :message unless @callbacks[:message]
|
12
|
+
raise MissingCallbackError, :output unless @callbacks[:output]
|
13
|
+
@state = :initialized
|
14
|
+
end
|
15
|
+
|
16
|
+
def <<(bytes)
|
17
|
+
@input_chain << bytes
|
18
|
+
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def on(name, &block)
|
23
|
+
@callbacks[name.to_sym] = block
|
24
|
+
|
25
|
+
nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def deliver(message)
|
29
|
+
raise InvalidStateError unless @state == :initialized
|
30
|
+
@output_chain << message.to_hash
|
31
|
+
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def create_input_chain
|
38
|
+
FilterChain::Chain.new do |chain|
|
39
|
+
chain.add(FilterChain::DemultiplexFilter.new)
|
40
|
+
chain.add(FilterChain::DeserializeFilter.new(:format => :json))
|
41
|
+
chain.add(FilterChain::Terminator.new { |message| message_handler(message) })
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_output_chain
|
46
|
+
FilterChain::Chain.new do |chain|
|
47
|
+
chain.add(FilterChain::SerializeFilter.new(:format => :json))
|
48
|
+
chain.add(FilterChain::MultiplexFilter.new)
|
49
|
+
chain.add(FilterChain::Terminator.new { |bytes| output_handler(bytes) })
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def message_handler(message)
|
54
|
+
@callbacks[:message].call(message)
|
55
|
+
end
|
56
|
+
|
57
|
+
def output_handler(bytes)
|
58
|
+
@callbacks[:output].call(bytes)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/oskie_rpc.rb
ADDED
data/oskie_rpc.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'oskie_rpc/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "oskie_rpc"
|
8
|
+
spec.version = OskieRpc::VERSION
|
9
|
+
spec.authors = ["Chad Remesch"]
|
10
|
+
spec.email = ["chad@remesch.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Simple easy to use transport agnostic RPC gem.}
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "filter_chain", "~> 0.1.1"
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "minitest"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: oskie_rpc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chad Remesch
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-08 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: filter_chain
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.1.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.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
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
|
+
- chad@remesch.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE.txt
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- lib/oskie_rpc.rb
|
85
|
+
- lib/oskie_rpc/exceptions.rb
|
86
|
+
- lib/oskie_rpc/message.rb
|
87
|
+
- lib/oskie_rpc/processor.rb
|
88
|
+
- lib/oskie_rpc/version.rb
|
89
|
+
- oskie_rpc.gemspec
|
90
|
+
homepage:
|
91
|
+
licenses:
|
92
|
+
- MIT
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options: []
|
96
|
+
require_paths:
|
97
|
+
- lib
|
98
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
requirements: []
|
109
|
+
rubyforge_project:
|
110
|
+
rubygems_version: 2.4.5
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Simple easy to use transport agnostic RPC gem.
|
114
|
+
test_files: []
|