cocainum 0.4 → 0.5
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 +4 -4
- data/lib/cocainum.rb +1 -98
- data/lib/cocainum/api.rb +0 -1
- data/lib/cocainum/overrides.rb +98 -0
- data/lib/cocainum/service.rb +15 -0
- data/lib/cocainum/storage.rb +23 -0
- data/lib/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9d9dcad4ba3243cfdf32ee8cf2dbea6d06c9563
|
4
|
+
data.tar.gz: ddd9e821b49a29800017eaa46343de21d93686ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f73780fad3e3f793ac5d55fbf9fe43a3803d746d5d7c541e1d5a5e38aba0effc4c8b0f24cc9dd80d578561baa4a28fde0ff4cee01fb875e61ddd0d0af84676b1
|
7
|
+
data.tar.gz: 1b5d37c785cf3e612659d88114488a494a52fe2683a736172b6a05569d4a248adbae9f3403c301af2795163e59e4834c4664c01aefb051ef2ea5be9d224c2f15
|
data/lib/cocainum.rb
CHANGED
@@ -6,102 +6,5 @@ require 'socket'
|
|
6
6
|
require 'nokogiri'
|
7
7
|
|
8
8
|
require 'cocaine/synchrony/service'
|
9
|
+
require 'cocainum/overrides'
|
9
10
|
|
10
|
-
class Cocaine::Locator < Cocaine::AbstractService
|
11
|
-
private
|
12
|
-
def do_resolve(name, df)
|
13
|
-
node = ''
|
14
|
-
if name.include? '/'
|
15
|
-
node, service_name = name.split('/', 2)
|
16
|
-
if node == (self.class.default_host == 'localhost' ? Socket.gethostname : self.class.default_host)
|
17
|
-
name = service_name
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
$log.debug "resolving service '#{name}'"
|
22
|
-
channel = invoke 0, name
|
23
|
-
channel.callback do |future|
|
24
|
-
begin
|
25
|
-
res = future.get
|
26
|
-
if node != '' && res[0][0] != node
|
27
|
-
raise Cocaine::ServiceError.new 'the specified service is not available in the group'
|
28
|
-
else
|
29
|
-
df.succeed future.get
|
30
|
-
end
|
31
|
-
rescue Exception => err
|
32
|
-
df.fail err
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class Nokogiri::XML::Node
|
39
|
-
TYPENAMES = {1=>'element',2=>'attribute',3=>'text',4=>'cdata',8=>'comment'}
|
40
|
-
def to_hash
|
41
|
-
[name.to_sym, case TYPENAMES[node_type]
|
42
|
-
when 'element'
|
43
|
-
node = {}
|
44
|
-
attribute_nodes.each {|attr| node[attr.name.to_sym] = attr.value}
|
45
|
-
children.each {|chld|
|
46
|
-
c = chld.to_hash
|
47
|
-
node[c[0].to_sym] = c[1] unless c[1] == nil
|
48
|
-
}
|
49
|
-
node
|
50
|
-
when 'text'
|
51
|
-
text.strip.empty? ? nil : text.strip
|
52
|
-
else
|
53
|
-
nil
|
54
|
-
end]
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
class Nokogiri::XML::Document
|
59
|
-
def to_hash; Hash[[root.to_hash]]; end
|
60
|
-
end
|
61
|
-
|
62
|
-
class Array
|
63
|
-
def to_xml(key)
|
64
|
-
map do |v|
|
65
|
-
if Hash === v
|
66
|
-
v.to_xml(false, key)
|
67
|
-
else
|
68
|
-
'<%s>%s</%s>' % [key, v, key]
|
69
|
-
end
|
70
|
-
end.join
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
class Hash
|
75
|
-
def to_xml(recurse = false, default_root = 'root')
|
76
|
-
attributes = []
|
77
|
-
children = []
|
78
|
-
each do |k, v|
|
79
|
-
if Hash === v
|
80
|
-
a, c = v.to_xml(true)
|
81
|
-
if c.size > 0
|
82
|
-
children << '<%s%s>%s</%s>' % [k, a.size > 0 ? ' ' + a.join(' ') : '', c.join, k]
|
83
|
-
else
|
84
|
-
children << '<%s%s />' % [k, a.size > 0 ? ' ' + a.join(' ') : '']
|
85
|
-
end
|
86
|
-
elsif Array === v
|
87
|
-
key = v.shift
|
88
|
-
children << '<%s>%s</%s>' % [k, v.to_xml(key), k]
|
89
|
-
else
|
90
|
-
attributes << '%s="%s"' % [k, v]
|
91
|
-
end
|
92
|
-
end
|
93
|
-
if recurse
|
94
|
-
[attributes, children]
|
95
|
-
else
|
96
|
-
if children.size > 1 || attributes.size > 0
|
97
|
-
if children.size > 0
|
98
|
-
'<%s%s>%s</%s>' % [default_root, attributes.size > 0 ? ' ' + attributes.join(' ') : '', children.join, default_root]
|
99
|
-
else
|
100
|
-
'<%s %s />' % [default_root, attributes.join(' ')]
|
101
|
-
end
|
102
|
-
else
|
103
|
-
children[0]
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
data/lib/cocainum/api.rb
CHANGED
@@ -0,0 +1,98 @@
|
|
1
|
+
class Cocaine::Locator < Cocaine::AbstractService
|
2
|
+
private
|
3
|
+
def do_resolve(name, df)
|
4
|
+
node = ''
|
5
|
+
if name.include? '/'
|
6
|
+
node, service_name = name.split('/', 2)
|
7
|
+
if node == (self.class.default_host == 'localhost' ? Socket.gethostname : self.class.default_host)
|
8
|
+
name = service_name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
$log.debug "resolving service '#{name}'"
|
13
|
+
channel = invoke 0, name
|
14
|
+
channel.callback do |future|
|
15
|
+
begin
|
16
|
+
res = future.get
|
17
|
+
if node != '' && res[0][0] != node
|
18
|
+
raise Cocaine::ServiceError.new 'the specified service is not available in the group'
|
19
|
+
else
|
20
|
+
df.succeed future.get
|
21
|
+
end
|
22
|
+
rescue Exception => err
|
23
|
+
df.fail err
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
class Nokogiri::XML::Node
|
30
|
+
TYPENAMES = {1=>'element',2=>'attribute',3=>'text',4=>'cdata',8=>'comment'}
|
31
|
+
def to_hash
|
32
|
+
[name.to_sym, case TYPENAMES[node_type]
|
33
|
+
when 'element'
|
34
|
+
node = {}
|
35
|
+
attribute_nodes.each {|attr| node[attr.name.to_sym] = attr.value}
|
36
|
+
children.each {|chld|
|
37
|
+
c = chld.to_hash
|
38
|
+
node[c[0].to_sym] = c[1] unless c[1] == nil
|
39
|
+
}
|
40
|
+
node
|
41
|
+
when 'text'
|
42
|
+
text.strip.empty? ? nil : text.strip
|
43
|
+
else
|
44
|
+
nil
|
45
|
+
end]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
class Nokogiri::XML::Document
|
50
|
+
def to_hash; Hash[[root.to_hash]]; end
|
51
|
+
end
|
52
|
+
|
53
|
+
class Array
|
54
|
+
def to_xml(key)
|
55
|
+
map do |v|
|
56
|
+
if Hash === v
|
57
|
+
v.to_xml(false, key)
|
58
|
+
else
|
59
|
+
'<%s>%s</%s>' % [key, v, key]
|
60
|
+
end
|
61
|
+
end.join
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class Hash
|
66
|
+
def to_xml(recurse = false, default_root = 'root')
|
67
|
+
attributes = []
|
68
|
+
children = []
|
69
|
+
each do |k, v|
|
70
|
+
if Hash === v
|
71
|
+
a, c = v.to_xml(true)
|
72
|
+
if c.size > 0
|
73
|
+
children << '<%s%s>%s</%s>' % [k, a.size > 0 ? ' ' + a.join(' ') : '', c.join, k]
|
74
|
+
else
|
75
|
+
children << '<%s%s />' % [k, a.size > 0 ? ' ' + a.join(' ') : '']
|
76
|
+
end
|
77
|
+
elsif Array === v
|
78
|
+
key = v.shift
|
79
|
+
children << '<%s>%s</%s>' % [k, v.to_xml(key), k]
|
80
|
+
else
|
81
|
+
attributes << '%s="%s"' % [k, v]
|
82
|
+
end
|
83
|
+
end
|
84
|
+
if recurse
|
85
|
+
[attributes, children]
|
86
|
+
else
|
87
|
+
if children.size > 1 || attributes.size > 0
|
88
|
+
if children.size > 0
|
89
|
+
'<%s%s>%s</%s>' % [default_root, attributes.size > 0 ? ' ' + attributes.join(' ') : '', children.join, default_root]
|
90
|
+
else
|
91
|
+
'<%s %s />' % [default_root, attributes.join(' ')]
|
92
|
+
end
|
93
|
+
else
|
94
|
+
children[0]
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'cocainum'
|
2
|
+
require 'cocaine/synchrony/service'
|
3
|
+
|
4
|
+
module Cocainum
|
5
|
+
class Service
|
6
|
+
|
7
|
+
def initialize(name)
|
8
|
+
@service = Cocaine::Synchrony::Service.new(name)
|
9
|
+
end
|
10
|
+
|
11
|
+
def enqueue(*args)
|
12
|
+
@service.enqueue(*args).collect
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'cocainum'
|
2
|
+
require 'cocaine/synchrony/service'
|
3
|
+
|
4
|
+
module Cocainum
|
5
|
+
class Storage
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@storage = Cocaine::Synchrony::Service.new('storage')
|
9
|
+
end
|
10
|
+
|
11
|
+
def write(namespace, key, value, tags = [])
|
12
|
+
@storage.write(namespace, key, value, tags).collect
|
13
|
+
end
|
14
|
+
|
15
|
+
def read(namespace, key)
|
16
|
+
@storage.read(namespace, key).collect
|
17
|
+
end
|
18
|
+
|
19
|
+
def find(namespace, tags)
|
20
|
+
@storage.find(namespace, tags).collect
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocainum
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Elmanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cocaine-framework-ruby
|
@@ -65,6 +65,9 @@ files:
|
|
65
65
|
- cocainum.gemspec
|
66
66
|
- lib/cocainum.rb
|
67
67
|
- lib/cocainum/api.rb
|
68
|
+
- lib/cocainum/overrides.rb
|
69
|
+
- lib/cocainum/service.rb
|
70
|
+
- lib/cocainum/storage.rb
|
68
71
|
- lib/version.rb
|
69
72
|
homepage:
|
70
73
|
licenses:
|