yz 0.0.1.alfa

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 60bae1e0b771cf5cd27680416680aac1e00120ff
4
+ data.tar.gz: fe7c47bb001d8c0fc7cdd34a3647adc9d5c851a3
5
+ SHA512:
6
+ metadata.gz: dae0f495b34293d086513e7c90365c9cab682150b8b871fbab5a0535ec3bfb809370c53138d69abee39a15426b226c4d4f832bb18121b7b0ffb64e2c05f94889
7
+ data.tar.gz: 8737913c74d241f8526b2ba28593fedbed2d940cdf3f146e130ef640f033abd97e1eb8da3c8fc49d41c888a0944f87296405b5c623e9006afa7e850b79c79286
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Ethan
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.
@@ -0,0 +1 @@
1
+ # Yz
File without changes
@@ -0,0 +1,37 @@
1
+ proc { |p| $:.unshift(p) unless $:.any? { |lp| File.expand_path(lp) == p } }.call(File.expand_path(File.dirname(__FILE__)))
2
+
3
+ require 'yz/version'
4
+
5
+ require 'ffi-rzmq'
6
+ require 'json'
7
+
8
+ module Yz
9
+ module Protocol
10
+ NAME = 'zy'
11
+ VERSION = '0.0'
12
+ FORMAT = 'json'
13
+ end
14
+
15
+ class Error < StandardError
16
+ end
17
+
18
+ class << self
19
+ def zmq_context
20
+ @zmq_context ||= begin
21
+ ZMQ::Context.new
22
+ end
23
+ end
24
+
25
+ def zmq_context=(zmq_context)
26
+ if @zmq_context
27
+ raise Yz::Error, "zmq_context is already set"
28
+ else
29
+ @zmq_context = zmq_context
30
+ end
31
+ end
32
+ end
33
+
34
+ autoload :Client, 'yz/client'
35
+ autoload :Request, 'yz/request'
36
+ autoload :Reply, 'yz/reply'
37
+ end
@@ -0,0 +1,40 @@
1
+ module Yz
2
+ class Client
3
+ def initialize(options = {})
4
+ # stringify symbol keys
5
+ @options = options.map { |k,v| {k.is_a?(Symbol) ? k.to_s : k => v} }.inject({}, &:update)
6
+ end
7
+
8
+ def request(object)
9
+ request = Request.new(object)
10
+ request.request_strings.each_with_index do |request_s, i|
11
+ flags = i < request.request_strings.size - 1 ? ZMQ::SNDMORE : 0
12
+ client_socket.send_string(request_s, flags)
13
+ end
14
+ reply_strings = []
15
+ more = true
16
+ while more
17
+ reply_message = ZMQ::Message.create || raise(ServerError, "failed to create message (errno = #{ZMQ::Util.errno})")
18
+ recv_rc = client_socket.recvmsg(reply_message)
19
+ reply_strings << reply_message.copy_out_string
20
+ reply_message.close
21
+ more = client_socket.more_parts?
22
+ end
23
+ Reply.new(reply_strings)
24
+ end
25
+
26
+ private
27
+ def client_socket
28
+ @client_socket ||= begin
29
+ Yz.zmq_context.socket(ZMQ::REQ).tap do |client_socket|
30
+ if @options['server_public_key'] || @options['client_public_key'] || @options['client_private_key']
31
+ client_socket.setsockopt(ZMQ::CURVE_SERVERKEY, @options['server_public_key'])
32
+ client_socket.setsockopt(ZMQ::CURVE_PUBLICKEY, @options['client_public_key'])
33
+ client_socket.setsockopt(ZMQ::CURVE_SECRETKEY, @options['client_private_key'])
34
+ end
35
+ client_socket.connect(@options['connect'])
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,23 @@
1
+ module Yz
2
+ class Reply
3
+ def initialize(reply_strings)
4
+ @reply_strings = reply_strings
5
+
6
+ @protocol_string = @reply_strings[0]
7
+
8
+ @protocol_parts = @protocol_string.strip.split(/ +/)
9
+ end
10
+
11
+ PROTOCOL_PARTS = ['name', 'version', 'format'].map(&:freeze).freeze
12
+
13
+ PROTOCOL_PARTS.each_with_index do |part, i|
14
+ define_method("protocol_#{part}") do
15
+ @protocol_parts[i]
16
+ end
17
+ end
18
+
19
+ def object
20
+ JSON.parse(@reply_strings[1])
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ module Yz
2
+ class Request
3
+ def initialize(object)
4
+ @object = object
5
+ end
6
+
7
+ def protocol_string
8
+ [Protocol::NAME, Protocol::VERSION, Protocol::FORMAT].join(' ')
9
+ end
10
+
11
+ def request_strings
12
+ @request_strings ||= [protocol_string, JSON.generate(@object)]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Yz
2
+ VERSION = '0.0.1.alfa'
3
+ end
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.any? { |lp| File.expand_path(lp) == File.expand_path(lib) }
4
+ require 'yz/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'yz'
8
+ spec.version = Yz::VERSION
9
+ spec.authors = ['Ethan']
10
+ spec.email = ['ethan@unth']
11
+ spec.summary = 'yz'
12
+ spec.description = 'yz'
13
+ spec.homepage = ''
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0") - ['.gitignore']
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'ffi-rzmq', '~> 2.0'
22
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yz
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alfa
5
+ platform: ruby
6
+ authors:
7
+ - Ethan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ffi-rzmq
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ description: yz
28
+ email:
29
+ - ethan@unth
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - Gemfile
35
+ - LICENSE.txt
36
+ - README.md
37
+ - Rakefile.rb
38
+ - lib/yz.rb
39
+ - lib/yz/client.rb
40
+ - lib/yz/reply.rb
41
+ - lib/yz/request.rb
42
+ - lib/yz/version.rb
43
+ - yz.gemspec
44
+ homepage: ''
45
+ licenses:
46
+ - MIT
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: 1.3.1
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.2.2
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: yz
68
+ test_files: []
69
+ has_rdoc: