seat-belt 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +29 -0
  3. data/.travis.yml +6 -0
  4. data/Changelog.md +55 -0
  5. data/Gemfile +15 -0
  6. data/Guardfile +13 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +705 -0
  9. data/Rakefile +1 -0
  10. data/ext/.gitkeep +0 -0
  11. data/lib/seatbelt.rb +37 -0
  12. data/lib/seatbelt/collections/collection.rb +56 -0
  13. data/lib/seatbelt/core.rb +15 -0
  14. data/lib/seatbelt/core/callee.rb +35 -0
  15. data/lib/seatbelt/core/eigenmethod.rb +150 -0
  16. data/lib/seatbelt/core/eigenmethod_proxy.rb +45 -0
  17. data/lib/seatbelt/core/ext/core_ext.rb +0 -0
  18. data/lib/seatbelt/core/gate.rb +198 -0
  19. data/lib/seatbelt/core/ghost_tunnel.rb +81 -0
  20. data/lib/seatbelt/core/implementation.rb +158 -0
  21. data/lib/seatbelt/core/interface.rb +51 -0
  22. data/lib/seatbelt/core/iterators/method_config.rb +50 -0
  23. data/lib/seatbelt/core/lookup_table.rb +101 -0
  24. data/lib/seatbelt/core/pool.rb +90 -0
  25. data/lib/seatbelt/core/property.rb +161 -0
  26. data/lib/seatbelt/core/proxy.rb +135 -0
  27. data/lib/seatbelt/core/synthesizeable.rb +50 -0
  28. data/lib/seatbelt/core/terminal.rb +59 -0
  29. data/lib/seatbelt/dependencies.rb +5 -0
  30. data/lib/seatbelt/document.rb +175 -0
  31. data/lib/seatbelt/errors.rb +1 -0
  32. data/lib/seatbelt/errors/errors.rb +150 -0
  33. data/lib/seatbelt/gate_config.rb +59 -0
  34. data/lib/seatbelt/ghost.rb +140 -0
  35. data/lib/seatbelt/models.rb +9 -0
  36. data/lib/seatbelt/seatbelt.rb +10 -0
  37. data/lib/seatbelt/synthesizer.rb +3 -0
  38. data/lib/seatbelt/synthesizers/document.rb +16 -0
  39. data/lib/seatbelt/synthesizers/mongoid.rb +16 -0
  40. data/lib/seatbelt/synthesizers/synthesizer.rb +146 -0
  41. data/lib/seatbelt/tape.rb +2 -0
  42. data/lib/seatbelt/tape_deck.rb +71 -0
  43. data/lib/seatbelt/tapes/tape.rb +105 -0
  44. data/lib/seatbelt/tapes/util/delegate.rb +56 -0
  45. data/lib/seatbelt/translator.rb +66 -0
  46. data/lib/seatbelt/version.rb +3 -0
  47. data/seatbelt.gemspec +27 -0
  48. data/spec/lib/seatbelt/core/eigenmethod_spec.rb +102 -0
  49. data/spec/lib/seatbelt/core/gate_spec.rb +521 -0
  50. data/spec/lib/seatbelt/core/ghost_tunnel_spec.rb +21 -0
  51. data/spec/lib/seatbelt/core/lookup_table_spec.rb +234 -0
  52. data/spec/lib/seatbelt/core/pool_spec.rb +270 -0
  53. data/spec/lib/seatbelt/core/proxy_spec.rb +108 -0
  54. data/spec/lib/seatbelt/core/terminal_spec.rb +184 -0
  55. data/spec/lib/seatbelt/document_spec.rb +287 -0
  56. data/spec/lib/seatbelt/gate_config_spec.rb +98 -0
  57. data/spec/lib/seatbelt/ghost_spec.rb +568 -0
  58. data/spec/lib/seatbelt/synthesizers/document_spec.rb +47 -0
  59. data/spec/lib/seatbelt/synthesizers/mongoid_spec.rb +134 -0
  60. data/spec/lib/seatbelt/synthesizers/synthesizer_spec.rb +112 -0
  61. data/spec/lib/seatbelt/tape_deck_spec.rb +180 -0
  62. data/spec/lib/seatbelt/tapes/tape_spec.rb +115 -0
  63. data/spec/lib/seatbelt/translator_spec.rb +108 -0
  64. data/spec/spec_helper.rb +16 -0
  65. data/spec/support/implementations/seatbelt_environment.rb +19 -0
  66. data/spec/support/shared_examples/shared_api_class.rb +7 -0
  67. data/spec/support/shared_examples/shared_collection_child.rb +7 -0
  68. data/spec/support/worlds/eigenmethod_world.rb +7 -0
  69. metadata +205 -0
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Seatbelt::GhostTunnel do
4
+ let(:tunnel){ Seatbelt::GhostTunnel }
5
+
6
+ it "is a module" do
7
+ expect(tunnel).to be_a Module
8
+ end
9
+
10
+ describe "methods" do
11
+
12
+ it "provides #enable_tunneling!" do
13
+ expect(tunnel).to respond_to(:enable_tunneling!)
14
+ end
15
+
16
+ it "provides #disable_tunneling!" do
17
+ expect(tunnel).to respond_to(:disable_tunneling!)
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,234 @@
1
+ require 'spec_helper'
2
+
3
+ describe Seatbelt::LookupTable do
4
+ let(:table){ Seatbelt::LookupTable.new }
5
+
6
+ it{ should be_a_kind_of(Array)}
7
+
8
+ describe "instance methods" do
9
+
10
+ it "provides #add_method" do
11
+ expect(subject).to respond_to(:add_method)
12
+ end
13
+
14
+ it "provides #set" do
15
+ expect(subject).to respond_to(:set)
16
+ end
17
+
18
+ it "provides #get" do
19
+ expect(subject).to respond_to(:get)
20
+ end
21
+
22
+ it "provides #unset" do
23
+ expect(subject).to respond_to(:unset)
24
+ end
25
+
26
+ it "provides #remove_method" do
27
+ expect(subject).to respond_to(:remove_method)
28
+ end
29
+
30
+ it "provides #find_method" do
31
+ expect(subject).to respond_to(:find_method)
32
+ end
33
+
34
+ it "provides #has?" do
35
+ expect(subject).to respond_to(:has?)
36
+ end
37
+
38
+ describe "#has?" do
39
+
40
+ before(:all) do
41
+ @table = Seatbelt::LookupTable.new
42
+ @options = {
43
+ :has_method => {
44
+ :scope => :class,
45
+ :block_required => false
46
+ }
47
+ }
48
+ @table.set(@options)
49
+ end
50
+
51
+ after(:all){ @table.clear }
52
+
53
+ describe "with the method name as argument" do
54
+
55
+ context "and a method with this name exists" do
56
+
57
+ it "returns true" do
58
+ expect(@table.has?(:has_method, scope: :class)).to be true
59
+ end
60
+
61
+ end
62
+
63
+ context "and no method wthis name exists" do
64
+
65
+ it "returns false" do
66
+ expect(@table.has?(:method_I_havent)).to be false
67
+ end
68
+
69
+ end
70
+ end
71
+
72
+ describe "with method configuration as argument" do
73
+
74
+ context "and a method with this configuration exists" do
75
+
76
+ it "returns true" do
77
+ options = {
78
+ :has_method => {
79
+ :scope => :class,
80
+ :block_required => false,
81
+ }
82
+ }
83
+ expect(@table.has?(options)).to be true
84
+ end
85
+ end
86
+
87
+ context "and no method with this configuration exists" do
88
+
89
+ it "returns false" do
90
+ options = {
91
+ :has_method => {
92
+ :scope => :class,
93
+ :block_required => true,
94
+ }
95
+ }
96
+ expect(@table.has?(options)).to be false
97
+ end
98
+ end
99
+ end
100
+
101
+ end
102
+
103
+ describe "#find_method" do
104
+ before do
105
+ @option_class = {
106
+ :foobar => {
107
+ :scope => :class,
108
+ :block_required => false
109
+ }
110
+ }
111
+
112
+ @option_instance = {
113
+ :foobar => {
114
+ :scope => :instance,
115
+ :block_required => true
116
+ }
117
+ }
118
+
119
+ table.set(@option_class)
120
+ table.set(@option_instance)
121
+ end
122
+
123
+ it "finds instance method by default" do
124
+ expect(table.find_method(:foobar, scope: :instance)).to eq @option_instance
125
+ end
126
+
127
+ end
128
+
129
+ describe "#get" do
130
+
131
+ describe "lookup has a method to get " do
132
+
133
+ before(:all) do
134
+ @table = Seatbelt::LookupTable.new
135
+ @options = {
136
+ :get_flights => {
137
+ :scope => :class,
138
+ :block_required => false,
139
+ }
140
+ }
141
+ @table.set(@options)
142
+ end
143
+
144
+ context "by method name" do
145
+
146
+ it "returns the method configuration" do
147
+ fetched_method = @table.get(:get_flights, scope: :class)
148
+ expect(fetched_method).to eq @options
149
+ end
150
+
151
+ end
152
+
153
+ context "by method configuration" do
154
+
155
+ it "returns the method configuration" do
156
+ fetched_method = @table.get(@options)
157
+ expect(fetched_method).to eq @options
158
+ end
159
+
160
+ end
161
+
162
+ end
163
+
164
+ describe "lookup has no method to get " do
165
+ before(:all){ @table = Seatbelt::LookupTable.new }
166
+
167
+ context "by method name" do
168
+
169
+ it "returns nil" do
170
+ expect(@table.get(:my_method)).to be nil
171
+ end
172
+
173
+ end
174
+
175
+ context "by method configuration" do
176
+
177
+ it "returns nil" do
178
+ expect(@table.get({:method => {:scope => :class}})).to be nil
179
+ end
180
+ end
181
+ end
182
+
183
+ end
184
+
185
+ describe "#remove_method" do
186
+ context "lookup table did not contain any methods" do
187
+
188
+ it "nothing happens" do
189
+ expect do
190
+ table.remove_method(:my_method)
191
+ end.to_not change{ table.size }
192
+ expect(table).to be_empty
193
+ end
194
+
195
+ end
196
+
197
+ describe "lookup table contains methods" do
198
+ context "and method to remove is included" do
199
+
200
+ let(:method_options) do
201
+ {
202
+ :my_method => {
203
+ :scope => :class,
204
+ :block_required => false
205
+ }
206
+ }
207
+ end
208
+
209
+ before { table.set(method_options) }
210
+ after { table.clear }
211
+
212
+ it "removes the method and returns the removed configuration" do
213
+ config = {}
214
+ expect do
215
+ config = table.remove_method(:my_method, scope: :class)
216
+ end.to change{ table.size }.by(-1)
217
+ expect(config).to be_a_kind_of(Hash)
218
+ expect(config).to eq method_options
219
+ end
220
+
221
+ end
222
+
223
+ context "and method to remove is not included" do
224
+
225
+ it "nothing happens" do
226
+ expect do
227
+ table.remove_method(:any_other_method)
228
+ end.to change{ table.size }.by(0)
229
+ end
230
+ end
231
+ end
232
+ end
233
+ end
234
+ end
@@ -0,0 +1,270 @@
1
+ require 'spec_helper'
2
+
3
+ describe Seatbelt::Pool::Api do
4
+ let(:pool){ Seatbelt::Pool::Api }
5
+
6
+ it "is a module" do
7
+ expect(pool).to be_a Module
8
+ end
9
+
10
+ describe "methods" do
11
+
12
+ it "provides #api_method" do
13
+ expect(pool).to respond_to(:api_method)
14
+ end
15
+
16
+ it "provides #lookup_tbl as class attribute accessor" do
17
+ expect(pool).to respond_to(:lookup_tbl)
18
+ end
19
+
20
+ describe '#lookup_tbl' do
21
+
22
+ it "is empty at the beginning" do
23
+ expect(pool.lookup_tbl).to be_empty
24
+ end
25
+
26
+ context "adding something to the lookup table" do
27
+
28
+ it "increases the lookup tables size" do
29
+ expect{ pool.lookup_tbl << 1 }.to change{ pool.lookup_tbl.size }.by(1)
30
+ end
31
+
32
+ end
33
+
34
+ context "removing something from the lookup table" do
35
+
36
+ it "decreases the lookup table size" do
37
+ expect do
38
+ pool.lookup_tbl.pop
39
+ pool.lookup_tbl
40
+ end.to change{ pool.lookup_tbl.size }.by(-1)
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+
47
+ describe "#api_method" do
48
+
49
+ context "its signature" do
50
+
51
+ after do
52
+ pool.instance_variable_set(:@lookup_tbl, Seatbelt::LookupTable.new)
53
+ end
54
+
55
+ it "requires at least a method name" do
56
+ expect do
57
+ pool.api_method
58
+ end.to raise_error(Seatbelt::Errors::ArgumentsMissmatchError)
59
+
60
+ expect do
61
+ pool.api_method :scope => :class,
62
+ :block_required => true
63
+ end.to raise_error(Seatbelt::Errors::MissingMetaMethodName)
64
+
65
+ end
66
+
67
+ end
68
+
69
+ context "adding meta-method definitions to the pools lookup_tbl" do
70
+
71
+ context "with just a meta-method name" do
72
+
73
+ it "uses default attributes" do
74
+ expect do
75
+ pool.api_method :sample_method
76
+ pool.lookup_tbl
77
+ end.to change{ pool.lookup_tbl.size }.by(1)
78
+ lookup_tbl_entry = pool.lookup_tbl.first
79
+
80
+ expect(lookup_tbl_entry).to be_instance_of(Hash)
81
+ expect(lookup_tbl_entry.keys.first).to eq :sample_method
82
+ expect(lookup_tbl_entry[:sample_method]).to_not be_empty
83
+
84
+ meta_method_options = lookup_tbl_entry[:sample_method]
85
+ expect(meta_method_options).to have_key(:scope)
86
+ expect(meta_method_options).to have_key(:block_required)
87
+ expect(meta_method_options[:scope]).to eq :instance
88
+ expect(meta_method_options[:block_required]).to eq false
89
+ end
90
+
91
+ end
92
+
93
+ context "with a meta-method name and a scope" do
94
+
95
+ it "uses the scope and default attributes" do
96
+ expect do
97
+ pool.api_method :find_scope,
98
+ :scope => :class
99
+ end.to change{ pool.lookup_tbl.size }.by(1)
100
+ expect(pool.lookup_tbl.size).to eq 2
101
+ lookup_tbl_entry = pool.lookup_tbl.last
102
+ expect(lookup_tbl_entry).to be_instance_of(Hash)
103
+ expect(lookup_tbl_entry.keys.first).to eq :find_scope
104
+ expect(lookup_tbl_entry[:find_scope]).to_not be_empty
105
+
106
+ meta_method_options = lookup_tbl_entry[:find_scope]
107
+ expect(meta_method_options).to have_key(:scope)
108
+ expect(meta_method_options).to have_key(:block_required)
109
+ expect(meta_method_options[:scope]).to eq :class
110
+ expect(meta_method_options[:block_required]).to eq false
111
+ end
112
+
113
+ end
114
+
115
+ context "with a meta-method name, a scope and block required" do
116
+
117
+ it "uses the passed arguments" do
118
+ expect do
119
+ pool.api_method :block_box,
120
+ :scope => :class,
121
+ :block_required => true
122
+ end.to change{ pool.lookup_tbl.size }.by(1)
123
+ expect(pool.lookup_tbl.size).to eq 3
124
+ lookup_tbl_entry = pool.lookup_tbl.last
125
+ expect(lookup_tbl_entry).to be_instance_of(Hash)
126
+ expect(lookup_tbl_entry.keys.first).to eq :block_box
127
+ expect(lookup_tbl_entry[:block_box]).to_not be_empty
128
+
129
+ meta_method_options = lookup_tbl_entry[:block_box]
130
+ expect(meta_method_options).to have_key(:scope)
131
+ expect(meta_method_options).to have_key(:block_required)
132
+ expect(meta_method_options[:scope]).to eq :class
133
+ expect(meta_method_options[:block_required]).to eq true
134
+ end
135
+
136
+ end
137
+
138
+ context "with a meta-method name and block_required" do
139
+
140
+ it "uses the block_required and default attributes" do
141
+ expect do
142
+ pool.api_method :parameter_box,
143
+ :block_required => true
144
+ end.to change{ pool.lookup_tbl.size }.by(1)
145
+ expect(pool.lookup_tbl.size).to eq 4
146
+ lookup_tbl_entry = pool.lookup_tbl.last
147
+ expect(lookup_tbl_entry).to be_instance_of(Hash)
148
+ expect(lookup_tbl_entry.keys.first).to eq :parameter_box
149
+ expect(lookup_tbl_entry[:parameter_box]).to_not be_empty
150
+
151
+ meta_method_options = lookup_tbl_entry[:parameter_box]
152
+ expect(meta_method_options).to have_key(:scope)
153
+ expect(meta_method_options).to have_key(:block_required)
154
+ expect(meta_method_options[:scope]).to eq :instance
155
+ expect(meta_method_options[:block_required]).to eq true
156
+ end
157
+
158
+ end
159
+
160
+ context "with a duplicated meta-method name" do
161
+
162
+ it "raises a Seatbelt::MetaMethodDuplicateError error" do
163
+ expect do
164
+ pool.api_method :block_box
165
+ end.to raise_error Seatbelt::Errors::MetaMethodDuplicateError
166
+ end
167
+ end
168
+
169
+ describe "#arity" do
170
+
171
+ context "specifying arguments" do
172
+
173
+ describe "without argument list" do
174
+
175
+ it "is an unsigned number of arguments passed to #api_method" do
176
+ pool.api_method :method_with_attrs, :args => [:a, :b, :c]
177
+ expect(pool.lookup_tbl.last[:method_with_attrs][:arity]).to eq 3
178
+ end
179
+
180
+ describe "and default values" do
181
+
182
+ it "is a signed number of arguments passed to #api_method" do
183
+ pool.api_method :method_with_defaults, :args => [:a, :b,"k=1"]
184
+ method = pool.lookup_tbl.last[:method_with_defaults]
185
+ expect(method[:arity]).to eq -3
186
+ end
187
+
188
+ end
189
+
190
+ describe "and block" do
191
+
192
+ it "ignores the block argument" do
193
+ pool.api_method :method_with_block, :args => [:a, :b, "&c"]
194
+ method = pool.lookup_tbl.last[:method_with_block]
195
+ expect(method[:arity]).to eq 2
196
+ end
197
+
198
+ describe "and default values" do
199
+
200
+ it "is a signed number of arguments passed to #api_method" do
201
+ args = [:a,"k=1", "&block"]
202
+ pool.api_method :method_block_defaults, :args => args
203
+ method = pool.lookup_tbl.last[:method_block_defaults]
204
+ expect(method[:arity]).to eq -2
205
+ end
206
+
207
+ end
208
+
209
+ end
210
+
211
+ end
212
+
213
+ describe "with arguments list" do
214
+
215
+ it "is a signed number of arguments passed to #api_method" do
216
+ pool.api_method :method_wth_args_list,
217
+ :args => ["a", "b", "c", "*f"]
218
+ method = pool.lookup_tbl.last[:method_wth_args_list][:arity]
219
+ expect(method).to eq -4
220
+ end
221
+
222
+ describe "and default values" do
223
+
224
+ it "is a signed number of arguments passed to #api_method" do
225
+ pool.api_method :method_args_a_defs,
226
+ :args => ["a", "b", "c=12","*f"]
227
+ method = pool.lookup_tbl.last[:method_args_a_defs]
228
+ expect(method[:arity]).to eq -3
229
+ end
230
+
231
+ end
232
+
233
+ describe "and block" do
234
+ it "ignores the block argument" do
235
+ pool.api_method :method_args_l_block, :args => [:a, "*f", "&c"]
236
+ method = pool.lookup_tbl.last[:method_args_l_block]
237
+ expect(method[:arity]).to eq -2
238
+ end
239
+
240
+ describe "and default values" do
241
+ it "is a signed number of arguments passed to #api_method" do
242
+ pool.api_method :method_args_a_defs_block,
243
+ :args => ["a", "b", "c=12","*f" , "&block"]
244
+ method = pool.lookup_tbl.last[:method_args_a_defs_block]
245
+ expect(method[:arity]).to eq -3
246
+ end
247
+ end
248
+
249
+ end
250
+
251
+ end
252
+
253
+ end
254
+
255
+ context "omitting arguments" do
256
+ it "is 0" do
257
+ pool.api_method :my_method
258
+ expect(pool.lookup_tbl.last[:my_method][:arity]).to equal 0
259
+ end
260
+ end
261
+
262
+ end
263
+
264
+ end
265
+
266
+ end
267
+
268
+ end
269
+
270
+ end