asir 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/.gitignore +11 -0
  2. data/Gemfile +16 -0
  3. data/README.textile +50 -0
  4. data/Rakefile +83 -0
  5. data/VERSION +1 -0
  6. data/asir.gemspec +36 -0
  7. data/asir.riterate.yml +114 -0
  8. data/bin/asir +6 -0
  9. data/doc/Rakefile +8 -0
  10. data/doc/asir-sequence.pic +84 -0
  11. data/doc/asir-sequence.svg +1559 -0
  12. data/doc/sequence.pic +430 -0
  13. data/example/asir_control.sh +24 -0
  14. data/example/asir_control_client_http.rb +14 -0
  15. data/example/asir_control_client_zmq.rb +15 -0
  16. data/example/config/asir_config.rb +63 -0
  17. data/example/delayed_service.rb +15 -0
  18. data/example/ex01.rb +12 -0
  19. data/example/ex02.rb +12 -0
  20. data/example/ex03.rb +19 -0
  21. data/example/ex04.rb +33 -0
  22. data/example/ex05.rb +16 -0
  23. data/example/ex06.rb +26 -0
  24. data/example/ex07.rb +28 -0
  25. data/example/ex08.rb +30 -0
  26. data/example/ex09.rb +25 -0
  27. data/example/ex10.rb +24 -0
  28. data/example/ex11.rb +48 -0
  29. data/example/ex12.rb +34 -0
  30. data/example/ex13.rb +35 -0
  31. data/example/ex14.rb +30 -0
  32. data/example/ex15.rb +13 -0
  33. data/example/ex16.rb +33 -0
  34. data/example/ex17.rb +41 -0
  35. data/example/ex18.rb +62 -0
  36. data/example/ex19.rb +32 -0
  37. data/example/ex20.rb +28 -0
  38. data/example/ex21.rb +28 -0
  39. data/example/ex22.rb +15 -0
  40. data/example/ex23.rb +20 -0
  41. data/example/ex24.rb +35 -0
  42. data/example/example_helper.rb +51 -0
  43. data/example/sample_service.rb +162 -0
  44. data/example/unsafe_service.rb +12 -0
  45. data/hack_night/README.txt +18 -0
  46. data/hack_night/exercise/prob-1.rb +18 -0
  47. data/hack_night/exercise/prob-2.rb +21 -0
  48. data/hack_night/exercise/prob-3.rb +16 -0
  49. data/hack_night/exercise/prob-4.rb +36 -0
  50. data/hack_night/exercise/prob-5.rb +36 -0
  51. data/hack_night/exercise/prob-6.rb +95 -0
  52. data/hack_night/exercise/prob-7.rb +34 -0
  53. data/hack_night/solution/math_service.rb +11 -0
  54. data/hack_night/solution/prob-1.rb +12 -0
  55. data/hack_night/solution/prob-2.rb +15 -0
  56. data/hack_night/solution/prob-3.rb +17 -0
  57. data/hack_night/solution/prob-4.rb +37 -0
  58. data/hack_night/solution/prob-5.rb +21 -0
  59. data/hack_night/solution/prob-6.rb +33 -0
  60. data/hack_night/solution/prob-7.rb +36 -0
  61. data/lab/phony_proc.rb +31 -0
  62. data/lib/asir.rb +253 -0
  63. data/lib/asir/additional_data.rb +25 -0
  64. data/lib/asir/channel.rb +130 -0
  65. data/lib/asir/client.rb +111 -0
  66. data/lib/asir/code_block.rb +57 -0
  67. data/lib/asir/code_more.rb +50 -0
  68. data/lib/asir/coder.rb +26 -0
  69. data/lib/asir/coder/base64.rb +19 -0
  70. data/lib/asir/coder/chain.rb +30 -0
  71. data/lib/asir/coder/identity.rb +23 -0
  72. data/lib/asir/coder/json.rb +30 -0
  73. data/lib/asir/coder/marshal.rb +17 -0
  74. data/lib/asir/coder/null.rb +23 -0
  75. data/lib/asir/coder/proc.rb +22 -0
  76. data/lib/asir/coder/sign.rb +48 -0
  77. data/lib/asir/coder/xml.rb +213 -0
  78. data/lib/asir/coder/yaml.rb +33 -0
  79. data/lib/asir/coder/zlib.rb +21 -0
  80. data/lib/asir/configuration.rb +32 -0
  81. data/lib/asir/error.rb +34 -0
  82. data/lib/asir/identity.rb +36 -0
  83. data/lib/asir/initialization.rb +23 -0
  84. data/lib/asir/log.rb +82 -0
  85. data/lib/asir/main.rb +396 -0
  86. data/lib/asir/message.rb +31 -0
  87. data/lib/asir/message/delay.rb +35 -0
  88. data/lib/asir/object_resolving.rb +15 -0
  89. data/lib/asir/result.rb +39 -0
  90. data/lib/asir/retry_behavior.rb +54 -0
  91. data/lib/asir/transport.rb +241 -0
  92. data/lib/asir/transport/beanstalk.rb +217 -0
  93. data/lib/asir/transport/broadcast.rb +34 -0
  94. data/lib/asir/transport/buffer.rb +115 -0
  95. data/lib/asir/transport/composite.rb +19 -0
  96. data/lib/asir/transport/connection_oriented.rb +180 -0
  97. data/lib/asir/transport/delay.rb +38 -0
  98. data/lib/asir/transport/delegation.rb +53 -0
  99. data/lib/asir/transport/fallback.rb +36 -0
  100. data/lib/asir/transport/file.rb +88 -0
  101. data/lib/asir/transport/http.rb +54 -0
  102. data/lib/asir/transport/local.rb +21 -0
  103. data/lib/asir/transport/null.rb +14 -0
  104. data/lib/asir/transport/payload_io.rb +52 -0
  105. data/lib/asir/transport/rack.rb +73 -0
  106. data/lib/asir/transport/retry.rb +41 -0
  107. data/lib/asir/transport/stream.rb +35 -0
  108. data/lib/asir/transport/subprocess.rb +30 -0
  109. data/lib/asir/transport/tcp_socket.rb +34 -0
  110. data/lib/asir/transport/webrick.rb +50 -0
  111. data/lib/asir/transport/zmq.rb +110 -0
  112. data/lib/asir/uuid.rb +32 -0
  113. data/lib/asir/version.rb +3 -0
  114. data/spec/const_get_speed_spec.rb +33 -0
  115. data/spec/debug_helper.rb +20 -0
  116. data/spec/example_spec.rb +88 -0
  117. data/spec/json_spec.rb +128 -0
  118. data/spec/spec_helper.rb +3 -0
  119. data/spec/xml_spec.rb +144 -0
  120. data/stylesheets/slides.css +105 -0
  121. metadata +173 -0
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'debug_helper'
3
+ $: << File.expand_path('../../lib', __FILE__)
@@ -0,0 +1,144 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ require 'asir/coder/xml'
3
+
4
+ describe "ASIR::Coder::XML" do
5
+ before(:each) do
6
+ @enc = ASIR::Coder::XML.new
7
+ @dec = @enc.dup
8
+ end
9
+
10
+ basic_objs = [ ]
11
+
12
+ [
13
+ nil,
14
+ true,
15
+ false,
16
+ ].each do | x |
17
+ basic_objs << x
18
+ it "should handle #{x.inspect}" do
19
+ xml = @enc.encode(x)
20
+ xml.should == "<#{x.class.name} />"
21
+ @dec.decode(xml).should == x
22
+ end
23
+ end
24
+
25
+ [
26
+ 1234,
27
+ 1.234,
28
+ ].each do | x |
29
+ basic_objs << x
30
+ it "should handle #{x.inspect}" do
31
+ xml = @enc.encode(x)
32
+ xml.should == "<#{x.class.name} v=\"#{x.to_s}\" />"
33
+ @dec.decode(xml).should == x
34
+ end
35
+ end
36
+
37
+ [
38
+ :symbol,
39
+ ].each do | x |
40
+ basic_objs << x
41
+ it "should handle #{x.inspect}" do
42
+ xml = @enc.encode(x)
43
+ xml.should == "<#{x.class.name} >#{x.to_s}</#{x.class.name}>"
44
+ @dec.decode(xml).should == x
45
+ end
46
+ end
47
+
48
+ [
49
+ 'String',
50
+ ].each do | x |
51
+ basic_objs << x
52
+ it "should handle #{x.inspect}" do
53
+ xml = @enc.encode(x)
54
+ xml.should == "<#{x.class.name} id=\"1\" >#{x.to_s}</#{x.class.name}>"
55
+ @dec.decode(xml).should == x
56
+ end
57
+ end
58
+
59
+ it "should handle empty Array" do
60
+ x = [ ]
61
+ xml = @enc.encode(x)
62
+ xml.should == "<#{x.class.name} id=\"1\" ></#{x.class.name}>"
63
+ @dec.decode(xml).should == x
64
+ end
65
+
66
+ it "should handle Array" do
67
+ x = [ *basic_objs ]
68
+ xml = @enc.encode(x)
69
+ xml.should =~ %r{\A<#{x.class.name} id=\"1\" ><NilClass /><TrueClass /><FalseClass /><Fixnum v="1234" /><Float v="1.234" /><Symbol >symbol</Symbol><String id=\"[^"]+\" >String</String></#{x.class.name}>\Z} # " emacs
70
+ @dec.decode(xml).should == x
71
+ end
72
+
73
+ it "should handle empty Hash" do
74
+ x = { }
75
+ xml = @enc.encode(x)
76
+ xml.should == "<#{x.class.name} id=\"1\" ></#{x.class.name}>"
77
+ @dec.decode(xml).should == x
78
+ end
79
+
80
+ it "should handle Hash" do
81
+ x = Hash[ *basic_objs.map{|e| e.inspect}.zip(basic_objs).flatten ]
82
+ xml = @enc.encode(x)
83
+ xml.should =~ %r{\A<#{x.class.name} id=\"1\" >}
84
+ xml.should =~ %r{</#{x.class.name}>\Z}
85
+ basic_objs.each do | v |
86
+ vx = @enc.dup.encode(v)
87
+ vx = vx.gsub(/id="[^"]+"/, 'id="\d+"')
88
+ xml.should =~ Regexp.new(vx)
89
+ xml.should =~ %r{ >#{v.inspect}</String>}
90
+ end
91
+ @dec.decode(xml).should == x
92
+ end
93
+
94
+ class ASIR::Coder::XML::Test
95
+ attr_accessor :a, :h, :o
96
+ end
97
+
98
+ it "should handle deep objects" do
99
+ x = ASIR::Coder::XML::Test.new
100
+ x.a = [ *basic_objs ]
101
+ x.h = Hash[ *basic_objs.map{|e| e.inspect}.zip(basic_objs).flatten ]
102
+ x.o = ASIR::Coder::XML::Test.new
103
+ x.o.a = 123
104
+ xml = @enc.encode(x)
105
+ xml.should =~ %r{<#{x.class.name.gsub('::', '.')} id=\"1\" >}
106
+ xml.should =~ %r{</#{x.class.name.gsub('::', '.')}>}
107
+ y = @dec.decode(xml)
108
+ y.a.should == x.a
109
+ y.h.should == x.h
110
+ y.o.class.should == ASIR::Coder::XML::Test
111
+ y.o.a.should == x.o.a
112
+ x.instance_variables.sort { |a, b| a.to_s <=> b.to_s}.should ==
113
+ y.instance_variables.sort { | a, b | a.to_s <=> b.to_s }
114
+ end
115
+
116
+ it "should handle multiple references to same objects." do
117
+ x = Hash[ *basic_objs.map{|e| e.inspect}.zip(basic_objs).flatten ]
118
+ y = [ 1, 2 ]
119
+ x = [ x, x, y, y ]
120
+ xml = @enc.encode(x)
121
+ y = @dec.decode(xml)
122
+ y[0].object_id.should == y[1].object_id
123
+ y[2].object_id.should == y[3].object_id
124
+ end
125
+
126
+ it "should handle self-referencing Array." do
127
+ x = [ 1 ]
128
+ x << x
129
+ xml = @enc.encode(x)
130
+ y = @dec.decode(xml)
131
+ y[0].should == x[0]
132
+ y[1].object_id.should == y.object_id
133
+ end
134
+
135
+ it "should handle self-referencing Hash." do
136
+ x = { :a => 1 }
137
+ x[:self] = x
138
+ xml = @enc.encode(x)
139
+ y = @dec.decode(xml)
140
+ y[:a].should == x[:a]
141
+ y[:self].object_id.should == y.object_id
142
+ end
143
+
144
+ end
@@ -0,0 +1,105 @@
1
+ * {
2
+ margin: 0;
3
+ padding: 0;
4
+ }
5
+
6
+ a:link {font-weight: bold; text-decoration: none; color: #ffffff}
7
+ a:visited {font-weight: bold; text-decoration: none; color: #ffffff}
8
+ a:hover {font-weight: bold; text-decoration: none; color: #ffffff}
9
+ a:active {font-weight: bold; text-decoration: none; color: #ffffff}
10
+
11
+ body {
12
+ font-family: Helvetica;
13
+ font-size: 30px;
14
+ color: #fff;
15
+ background: #111;
16
+ }
17
+
18
+ table {
19
+ font-size: 0.8em;
20
+ border: 4px solid #555753;
21
+ }
22
+
23
+ th, td {
24
+ border: 2px solid #555753;
25
+ padding: 5px;
26
+ margin: 0;
27
+ }
28
+
29
+ pre {
30
+ font-family: monospace;
31
+ font-size: 0.8em;
32
+ }
33
+
34
+ blockquote {
35
+ padding: 0 0 0 1em;
36
+ font-size: 1.4em;
37
+ font-family: Georgia, serif;
38
+ font-style: italic;
39
+ }
40
+
41
+ ul {
42
+ padding: 0 0 0 1em;
43
+ }
44
+
45
+ #slides {
46
+ overflow: hidden;
47
+ text-align: left;
48
+ }
49
+
50
+ #track {
51
+ width: 1000000px;
52
+ overflow: hidden;
53
+ }
54
+
55
+ #track > div {
56
+ float: left;
57
+ overflow: hidden;
58
+ }
59
+
60
+ #track > div .content {
61
+ margin: 0 0.6em;
62
+ }
63
+
64
+ #track > div .content h1 {
65
+ margin-bottom: 0.1em;
66
+ }
67
+
68
+ #track > div .content h1 strong {
69
+ text-decoration: underline;
70
+ }
71
+
72
+ .svg {
73
+ width: 90%;
74
+ // doesn't appear to work for <object> in Safari -- kurt 2010/12/03
75
+ // height: auto;
76
+ // doesn't matter since CSS does appear to work on <object> height at all -- kurt 2010/12/03
77
+ // See hardcoded <object ... width="90%" height="67%" in riterate/bin/riterate
78
+ // 4/3 aspect?
79
+ height: 67%;
80
+ }
81
+
82
+ .code {
83
+ border: .2em solid #555753;
84
+ background: #eeeeec;
85
+ color: #111;
86
+ padding: .2em;
87
+ margin: .5em 0 .5em 0;
88
+ }
89
+
90
+ .code_output {
91
+ border: .2em solid #555753;
92
+ background: #eeeeec;
93
+ color: #111;
94
+ padding: .2em;
95
+ margin: .5em 0 .5em 0;
96
+ }
97
+
98
+ .code_output_highlight {
99
+ border: .2em solid @555753;
100
+ background: #202040;
101
+ color: #f0f020;
102
+ padding: .2em;
103
+ margin: .1em 0 .1em 0;
104
+ }
105
+
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asir
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kurt Stephens
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-03 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Abstracting Services in Ruby
15
+ email: ks.ruby@kurtstephens.com
16
+ executables:
17
+ - asir
18
+ extensions: []
19
+ extra_rdoc_files:
20
+ - README.textile
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - README.textile
25
+ - Rakefile
26
+ - VERSION
27
+ - asir.gemspec
28
+ - asir.riterate.yml
29
+ - bin/asir
30
+ - doc/Rakefile
31
+ - doc/asir-sequence.pic
32
+ - doc/asir-sequence.svg
33
+ - doc/sequence.pic
34
+ - example/asir_control.sh
35
+ - example/asir_control_client_http.rb
36
+ - example/asir_control_client_zmq.rb
37
+ - example/config/asir_config.rb
38
+ - example/delayed_service.rb
39
+ - example/ex01.rb
40
+ - example/ex02.rb
41
+ - example/ex03.rb
42
+ - example/ex04.rb
43
+ - example/ex05.rb
44
+ - example/ex06.rb
45
+ - example/ex07.rb
46
+ - example/ex08.rb
47
+ - example/ex09.rb
48
+ - example/ex10.rb
49
+ - example/ex11.rb
50
+ - example/ex12.rb
51
+ - example/ex13.rb
52
+ - example/ex14.rb
53
+ - example/ex15.rb
54
+ - example/ex16.rb
55
+ - example/ex17.rb
56
+ - example/ex18.rb
57
+ - example/ex19.rb
58
+ - example/ex20.rb
59
+ - example/ex21.rb
60
+ - example/ex22.rb
61
+ - example/ex23.rb
62
+ - example/ex24.rb
63
+ - example/example_helper.rb
64
+ - example/sample_service.rb
65
+ - example/unsafe_service.rb
66
+ - hack_night/README.txt
67
+ - hack_night/exercise/prob-1.rb
68
+ - hack_night/exercise/prob-2.rb
69
+ - hack_night/exercise/prob-3.rb
70
+ - hack_night/exercise/prob-4.rb
71
+ - hack_night/exercise/prob-5.rb
72
+ - hack_night/exercise/prob-6.rb
73
+ - hack_night/exercise/prob-7.rb
74
+ - hack_night/solution/math_service.rb
75
+ - hack_night/solution/prob-1.rb
76
+ - hack_night/solution/prob-2.rb
77
+ - hack_night/solution/prob-3.rb
78
+ - hack_night/solution/prob-4.rb
79
+ - hack_night/solution/prob-5.rb
80
+ - hack_night/solution/prob-6.rb
81
+ - hack_night/solution/prob-7.rb
82
+ - lab/phony_proc.rb
83
+ - lib/asir.rb
84
+ - lib/asir/additional_data.rb
85
+ - lib/asir/channel.rb
86
+ - lib/asir/client.rb
87
+ - lib/asir/code_block.rb
88
+ - lib/asir/code_more.rb
89
+ - lib/asir/coder.rb
90
+ - lib/asir/coder/base64.rb
91
+ - lib/asir/coder/chain.rb
92
+ - lib/asir/coder/identity.rb
93
+ - lib/asir/coder/json.rb
94
+ - lib/asir/coder/marshal.rb
95
+ - lib/asir/coder/null.rb
96
+ - lib/asir/coder/proc.rb
97
+ - lib/asir/coder/sign.rb
98
+ - lib/asir/coder/xml.rb
99
+ - lib/asir/coder/yaml.rb
100
+ - lib/asir/coder/zlib.rb
101
+ - lib/asir/configuration.rb
102
+ - lib/asir/error.rb
103
+ - lib/asir/identity.rb
104
+ - lib/asir/initialization.rb
105
+ - lib/asir/log.rb
106
+ - lib/asir/main.rb
107
+ - lib/asir/message.rb
108
+ - lib/asir/message/delay.rb
109
+ - lib/asir/object_resolving.rb
110
+ - lib/asir/result.rb
111
+ - lib/asir/retry_behavior.rb
112
+ - lib/asir/transport.rb
113
+ - lib/asir/transport/beanstalk.rb
114
+ - lib/asir/transport/broadcast.rb
115
+ - lib/asir/transport/buffer.rb
116
+ - lib/asir/transport/composite.rb
117
+ - lib/asir/transport/connection_oriented.rb
118
+ - lib/asir/transport/delay.rb
119
+ - lib/asir/transport/delegation.rb
120
+ - lib/asir/transport/fallback.rb
121
+ - lib/asir/transport/file.rb
122
+ - lib/asir/transport/http.rb
123
+ - lib/asir/transport/local.rb
124
+ - lib/asir/transport/null.rb
125
+ - lib/asir/transport/payload_io.rb
126
+ - lib/asir/transport/rack.rb
127
+ - lib/asir/transport/retry.rb
128
+ - lib/asir/transport/stream.rb
129
+ - lib/asir/transport/subprocess.rb
130
+ - lib/asir/transport/tcp_socket.rb
131
+ - lib/asir/transport/webrick.rb
132
+ - lib/asir/transport/zmq.rb
133
+ - lib/asir/uuid.rb
134
+ - lib/asir/version.rb
135
+ - spec/const_get_speed_spec.rb
136
+ - spec/debug_helper.rb
137
+ - spec/example_spec.rb
138
+ - spec/json_spec.rb
139
+ - spec/spec_helper.rb
140
+ - spec/xml_spec.rb
141
+ - stylesheets/slides.css
142
+ homepage: http://github.com/kstephens/abstracting_services_in_ruby
143
+ licenses: []
144
+ post_install_message:
145
+ rdoc_options:
146
+ - --charset=UTF-8
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ! '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ requirements: []
162
+ rubyforge_project:
163
+ rubygems_version: 1.8.15
164
+ signing_key:
165
+ specification_version: 3
166
+ summary: Abstracting Services in Ruby
167
+ test_files:
168
+ - spec/const_get_speed_spec.rb
169
+ - spec/debug_helper.rb
170
+ - spec/example_spec.rb
171
+ - spec/json_spec.rb
172
+ - spec/spec_helper.rb
173
+ - spec/xml_spec.rb