bunny 0.2.0 → 0.3.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.
@@ -1,171 +0,0 @@
1
- require 'rubygems'
2
- require 'json'
3
-
4
- name = 'amqp-0.8.json'
5
- path = File.dirname(__FILE__)+'/'+name
6
- s = JSON.parse(File.read(path))
7
-
8
- # require 'pp'
9
- # pp(s)
10
- # exit
11
-
12
- require 'erb'
13
-
14
- puts ERB.new(%q[
15
- #:stopdoc:
16
- # this file was autogenerated on <%= Time.now.to_s %>
17
- # using <%= name.ljust(16) %> (mtime: <%= File.mtime(path) %>)
18
- #
19
- # DO NOT EDIT! (edit protocol/codegen.rb instead, and run `rake codegen`)
20
-
21
- module Transport
22
- class Frame
23
- def self.types
24
- @types ||= {}
25
- end
26
-
27
- def self.Frame id
28
- (@_base_frames ||= {})[id] ||= Class.new(Frame) do
29
- class_eval %[
30
- def self.inherited klass
31
- klass.const_set(:ID, #{id})
32
- Frame.types[#{id}] = klass
33
- end
34
- ]
35
- end
36
- end
37
-
38
- <%- s['constants'].select{|c| (1..8).include? c['value'] }.each do |c| -%>
39
- class <%= c['name'].gsub(/^FRAME-/,'').split('-').map{|w| w.downcase.capitalize}.join.ljust(9) -%> < Frame( <%= c['value'] -%> ); end
40
- <%- end -%>
41
-
42
- FOOTER = <%= frame_end = s['constants'].find{|c| c['name'] == 'FRAME-END' }['value'] %>
43
- end
44
- end
45
-
46
- module Protocol
47
- HEADER = <%= s['name'].dump %>.freeze
48
- VERSION_MAJOR = <%= s['major-version'] %>
49
- VERSION_MINOR = <%= s['minor-version'] %>
50
- PORT = <%= s['port'] %>
51
-
52
- RESPONSES = {
53
- <%- s['constants'].select{|c| c['value'] != frame_end and (200..500).include? c['value'] }.each do |c| -%>
54
- <%= c['value'] %> => :<%= c['name'].tr('-', '_').gsub(/^FRAME_/,'').upcase -%>,
55
- <%- end -%>
56
- }
57
-
58
- FIELDS = [
59
- <%- s['domains'].select{|d| d.first == d.last }.each do |d| -%>
60
- :<%= d.first -%>,
61
- <%- end -%>
62
- ]
63
-
64
- class Class
65
- class << self
66
- FIELDS.each do |f|
67
- class_eval %[
68
- def #{f} name
69
- properties << [ :#{f}, name ] unless properties.include?([:#{f}, name])
70
- attr_accessor name
71
- end
72
- ]
73
- end
74
-
75
- def properties() @properties ||= [] end
76
-
77
- def id() self::ID end
78
- def name() self::NAME end
79
- end
80
-
81
- class Method
82
- class << self
83
- FIELDS.each do |f|
84
- class_eval %[
85
- def #{f} name
86
- arguments << [ :#{f}, name ] unless arguments.include?([:#{f}, name])
87
- attr_accessor name
88
- end
89
- ]
90
- end
91
-
92
- def arguments() @arguments ||= [] end
93
-
94
- def parent() Protocol.const_get(self.to_s[/Protocol::(.+?)::/,1]) end
95
- def id() self::ID end
96
- def name() self::NAME end
97
- end
98
-
99
- def == b
100
- self.class.arguments.inject(true) do |eql, (type, name)|
101
- eql and __send__("#{name}") == b.__send__("#{name}")
102
- end
103
- end
104
- end
105
-
106
- def self.methods() @methods ||= {} end
107
-
108
- def self.Method(id, name)
109
- @_base_methods ||= {}
110
- @_base_methods[id] ||= ::Class.new(Method) do
111
- class_eval %[
112
- def self.inherited klass
113
- klass.const_set(:ID, #{id})
114
- klass.const_set(:NAME, :#{name.to_s})
115
- klass.parent.methods[#{id}] = klass
116
- klass.parent.methods[klass::NAME] = klass
117
- end
118
- ]
119
- end
120
- end
121
- end
122
-
123
- def self.classes() @classes ||= {} end
124
-
125
- def self.Class(id, name)
126
- @_base_classes ||= {}
127
- @_base_classes[id] ||= ::Class.new(Class) do
128
- class_eval %[
129
- def self.inherited klass
130
- klass.const_set(:ID, #{id})
131
- klass.const_set(:NAME, :#{name.to_s})
132
- Protocol.classes[#{id}] = klass
133
- Protocol.classes[klass::NAME] = klass
134
- end
135
- ]
136
- end
137
- end
138
- end
139
-
140
- module Protocol
141
- <%- s['classes'].each do |c| -%>
142
- class <%= c['name'].capitalize.ljust(12) %> < Class( <%= c['id'].to_s.rjust(3) %>, :<%= c['name'].ljust(12) %> ); end
143
- <%- end -%>
144
-
145
- <%- s['classes'].each do |c| -%>
146
- class <%= c['name'].capitalize %>
147
- <%- c['properties'].each do |p| -%>
148
- <%= p['type'].ljust(10) %> :<%= p['name'].tr('-','_') %>
149
- <%- end if c['properties'] -%>
150
-
151
- <%- c['methods'].each do |m| -%>
152
- class <%= m['name'].capitalize.gsub(/-(.)/){ "#{$1.upcase}"}.ljust(12) %> < Method( <%= m['id'].to_s.rjust(3) %>, :<%= m['name'].tr('- ','_').ljust(14) %> ); end
153
- <%- end -%>
154
-
155
- <%- c['methods'].each do |m| -%>
156
- class <%= m['name'].capitalize.gsub(/-(.)/){ "#{$1.upcase}"} %>
157
- <%- m['arguments'].each do |a| -%>
158
- <%- if a['domain'] -%>
159
- <%= s['domains'].find{|k,v| k == a['domain']}.last.ljust(10) %> :<%= a['name'].tr('- ','_') %>
160
- <%- else -%>
161
- <%= a['type'].ljust(10) %> :<%= a['name'].tr('- ','_') %>
162
- <%- end -%>
163
- <%- end if m['arguments'] -%>
164
- end
165
-
166
- <%- end -%>
167
- end
168
-
169
- <%- end -%>
170
- end
171
- ].gsub!(/^ /,''), nil, '>-%').result(binding)