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,115 @@
1
+ require 'spec_helper'
2
+
3
+ describe Seatbelt::Tape do
4
+
5
+ describe "class methods" do
6
+
7
+ it "provides #answers" do
8
+ expect(Seatbelt::Tape).to respond_to(:answers)
9
+ end
10
+
11
+ it "provides #translate" do
12
+ expect(Seatbelt::Tape).to respond_to(:translate)
13
+ end
14
+
15
+ it "provides #listen_to" do
16
+ expect(Seatbelt::Tape).to respond_to(:listen_to)
17
+ end
18
+
19
+ it "provides #play_tape" do
20
+ expect(Seatbelt::Tape).to respond_to(:play_tape)
21
+ end
22
+
23
+ it "provides #tape_deck" do
24
+ expect(Seatbelt::Tape).to respond_to(:tape_deck)
25
+ end
26
+
27
+ describe "#answers" do
28
+
29
+ before(:all) do
30
+ class RSpecTape < Seatbelt::Tape;end
31
+ end
32
+
33
+ it "is a store to hold answers for the tape" do
34
+ expect do
35
+ RSpecTape.class_eval do
36
+ translate /hey/ do |sentence|
37
+ end
38
+ end
39
+ end.to change{ RSpecTape.answers.size }.by(1)
40
+ end
41
+
42
+ end
43
+
44
+ describe "#translate" do
45
+
46
+ context "playing other tapes" do
47
+
48
+ before(:all) do
49
+ class FooTape < Seatbelt::Tape
50
+
51
+ translate /Hello Howdie!/ do |sentence, data|
52
+ play_tape(BarTape, :section => "No man!")
53
+ end
54
+
55
+ translate /Gimme (\d+) beers!/ do |count_of_beer|
56
+ play_tape(:section => "Want the bill for #{count_of_beer} beer")
57
+ end
58
+
59
+ translate /Want the bill for (\d+) beer/ do |beer_amount|
60
+ costs_of_beer = 2
61
+ sum = 2 * beer_amount.to_i
62
+ "Cost #{sum} bucks."
63
+ end
64
+
65
+ translate /Send me (\d+) postcards from (\w+)/ do |sentence,
66
+ post_card_count,
67
+ location|
68
+
69
+ play_tape(PostcardTape, :section => "send #{post_card_count}")
70
+ end
71
+ end
72
+
73
+ class BarTape < Seatbelt::Tape
74
+
75
+ translate /No man!/ do |sentence, data|
76
+ "My query is: #{sentence}"
77
+ end
78
+
79
+ end
80
+
81
+ class PostcardTape < Seatbelt::Tape
82
+
83
+ end
84
+
85
+ class Foo
86
+ include Seatbelt::TapeDeck
87
+
88
+ use_tapes FooTape,
89
+ BarTape
90
+ end
91
+ end
92
+
93
+ it "calls the same tape if tape name is omitted" do
94
+ result = Foo.respond("Gimme 2 beers!")
95
+ expect(result).to eq("Cost 4 bucks.")
96
+ end
97
+
98
+ it "calls an answer of a different tape if tape name is given" do
99
+ result = Foo.respond("Hello Howdie!")
100
+ expect(result).to eq "My query is: No man!"
101
+ end
102
+
103
+ it "raises an error if a unknow tape is called" do
104
+ expect do
105
+ Foo.respond("Send me 2 postcards from London")
106
+ end.to raise_error(Seatbelt::Errors::NoTapeFoundForQueryError)
107
+ end
108
+
109
+ end
110
+
111
+ end
112
+
113
+ end
114
+
115
+ end
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Seatbelt::Translator" do
4
+
5
+ describe "class methods" do
6
+
7
+ it "provides #tell_me" do
8
+ expect(Seatbelt::Translator).to respond_to(:tell_me)
9
+ end
10
+
11
+ it "provides #setup" do
12
+ expect(Seatbelt::Translator).to respond_to(:setup)
13
+ end
14
+
15
+ describe "#setup" do
16
+
17
+ it "configures the model namespace" do
18
+ Seatbelt::Translator.setup do |config|
19
+ config.namespace = "Seatbelt::Models::"
20
+ end
21
+
22
+ expect(Seatbelt::Translator.config.namespace).to eq "Seatbelt::Models::"
23
+
24
+ end
25
+
26
+ it "configures the model name regular expression" do
27
+ Seatbelt::Translator.setup do |config|
28
+ config.name_regex = /\w{1,}/
29
+ end
30
+
31
+ expect(Seatbelt::Translator.config.name_regex).to eq /\w{1,}/
32
+ end
33
+
34
+ it "configures the default model class for delegating questions" do
35
+ Seatbelt::Translator.setup do |config|
36
+ config.default_model_class = "Offer"
37
+ end
38
+
39
+ expect(Seatbelt::Translator.config.default_model_class).to eq "Offer"
40
+ end
41
+
42
+ end
43
+
44
+ describe "#tell_me" do
45
+
46
+ before(:all) do
47
+ Seatbelt::Translator.config.name_regex = nil
48
+ Seatbelt::Translator.setup do |c|
49
+ c.namespace = "Seatbelt::Models::"
50
+ c.default_model_class = "Offer"
51
+ end
52
+ class HotelSampleTape < Seatbelt::Tape
53
+ translate /Show me (\d+) of the (\w+) in (\w+)/ do |sentence,
54
+ count,
55
+ price_type,
56
+ location|
57
+
58
+
59
+ tape_deck.to_s
60
+ end
61
+
62
+ translate /(\d+) (persons|person) want to travel for (\d+) (days|weeks|months) beginning at (.+) to (\w+)./i do |question,data|
63
+ []
64
+ end
65
+
66
+ end
67
+ Seatbelt::Models::Hotel.class_eval { include Seatbelt::TapeDeck }
68
+ Seatbelt::Models::Hotel.add_tape HotelSampleTape
69
+ end
70
+
71
+ it "query starts with responsible model" do
72
+ query = "Hotel: Show me 2 of the cheapest in London"
73
+ result = Seatbelt::Translator.tell_me query
74
+ expect(result).to eq "Seatbelt::Models::Hotel"
75
+ end
76
+
77
+ context "if responsible model name is omitted" do
78
+
79
+ before(:all) do
80
+ Seatbelt::Models::Offer.class_eval { include Seatbelt::TapeDeck }
81
+ class OfferSampleTape < Seatbelt::Tape
82
+ translate /Find hotels in (\w+)/ do |sentence, city|
83
+ tape_deck
84
+ end
85
+ end
86
+ Seatbelt::Models::Offer.add_tape OfferSampleTape
87
+ end
88
+
89
+ it "then calls the Offer model" do
90
+ expect(Seatbelt::Translator.tell_me "Find hotels in Barcelona").to eq\
91
+ Seatbelt::Models::Offer
92
+ end
93
+
94
+ end
95
+
96
+ it "gets the tape that responds to the query and plays the tape" do
97
+ query = "Hotel: 3 persons want to travel for 10 days beginning at next friday to Finnland."
98
+ result = Seatbelt::Translator.tell_me query
99
+
100
+ expect(result).to be_instance_of Array
101
+ end
102
+
103
+ end
104
+
105
+
106
+ end
107
+
108
+ end
@@ -0,0 +1,16 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+
4
+ require 'rspec'
5
+ #
6
+
7
+ require 'seatbelt'
8
+
9
+ require 'mongoid'
10
+
11
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
12
+
13
+ RSpec.configure do |config|
14
+ config.include EigenmethodWorld
15
+ end
16
+
@@ -0,0 +1,19 @@
1
+ ["Hotel", "Offer", "Flight"].each do |model|
2
+ code = <<-RUBY
3
+ module Seatbelt
4
+ module Models
5
+ class #{model}
6
+ include Seatbelt::Document
7
+ include Seatbelt::Ghost
8
+ end
9
+ end
10
+
11
+ module Collections
12
+ class #{model}Collection < Seatbelt::Collections::Collection
13
+
14
+ end
15
+ end
16
+ end
17
+ RUBY
18
+ eval(code)
19
+ end
@@ -0,0 +1,7 @@
1
+ shared_examples_for "ApiClass" do
2
+
3
+ it "that has #api_method class method" do
4
+ expect(subject.class).to respond_to(:api_method)
5
+ end
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ shared_examples_for "CollectionChild" do |type|
2
+
3
+ it "that has #api_method class method" do
4
+ expect(type.superclass).to eq Seatbelt::Collections::Collection
5
+ end
6
+
7
+ end
@@ -0,0 +1,7 @@
1
+ module EigenmethodWorld
2
+
3
+ def stub_eigenmethods(klass)
4
+ klass.stub(:eigenmethods).and_return([])
5
+ end
6
+
7
+ end
metadata ADDED
@@ -0,0 +1,205 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: seat-belt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.10.0
5
+ platform: ruby
6
+ authors:
7
+ - Daniel Schmidt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: virtus
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: activemodel
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: |-
84
+ Tool to define implementation interfaces that should be decoupled from their
85
+ implementations. (A Ruby header file approach.)
86
+ email:
87
+ - dsci@code79.net
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".travis.yml"
94
+ - Changelog.md
95
+ - Gemfile
96
+ - Guardfile
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - ext/.gitkeep
101
+ - lib/seatbelt.rb
102
+ - lib/seatbelt/collections/collection.rb
103
+ - lib/seatbelt/core.rb
104
+ - lib/seatbelt/core/callee.rb
105
+ - lib/seatbelt/core/eigenmethod.rb
106
+ - lib/seatbelt/core/eigenmethod_proxy.rb
107
+ - lib/seatbelt/core/ext/core_ext.rb
108
+ - lib/seatbelt/core/gate.rb
109
+ - lib/seatbelt/core/ghost_tunnel.rb
110
+ - lib/seatbelt/core/implementation.rb
111
+ - lib/seatbelt/core/interface.rb
112
+ - lib/seatbelt/core/iterators/method_config.rb
113
+ - lib/seatbelt/core/lookup_table.rb
114
+ - lib/seatbelt/core/pool.rb
115
+ - lib/seatbelt/core/property.rb
116
+ - lib/seatbelt/core/proxy.rb
117
+ - lib/seatbelt/core/synthesizeable.rb
118
+ - lib/seatbelt/core/terminal.rb
119
+ - lib/seatbelt/dependencies.rb
120
+ - lib/seatbelt/document.rb
121
+ - lib/seatbelt/errors.rb
122
+ - lib/seatbelt/errors/errors.rb
123
+ - lib/seatbelt/gate_config.rb
124
+ - lib/seatbelt/ghost.rb
125
+ - lib/seatbelt/models.rb
126
+ - lib/seatbelt/seatbelt.rb
127
+ - lib/seatbelt/synthesizer.rb
128
+ - lib/seatbelt/synthesizers/document.rb
129
+ - lib/seatbelt/synthesizers/mongoid.rb
130
+ - lib/seatbelt/synthesizers/synthesizer.rb
131
+ - lib/seatbelt/tape.rb
132
+ - lib/seatbelt/tape_deck.rb
133
+ - lib/seatbelt/tapes/tape.rb
134
+ - lib/seatbelt/tapes/util/delegate.rb
135
+ - lib/seatbelt/translator.rb
136
+ - lib/seatbelt/version.rb
137
+ - seatbelt.gemspec
138
+ - spec/lib/seatbelt/core/eigenmethod_spec.rb
139
+ - spec/lib/seatbelt/core/gate_spec.rb
140
+ - spec/lib/seatbelt/core/ghost_tunnel_spec.rb
141
+ - spec/lib/seatbelt/core/lookup_table_spec.rb
142
+ - spec/lib/seatbelt/core/pool_spec.rb
143
+ - spec/lib/seatbelt/core/proxy_spec.rb
144
+ - spec/lib/seatbelt/core/terminal_spec.rb
145
+ - spec/lib/seatbelt/document_spec.rb
146
+ - spec/lib/seatbelt/gate_config_spec.rb
147
+ - spec/lib/seatbelt/ghost_spec.rb
148
+ - spec/lib/seatbelt/synthesizers/document_spec.rb
149
+ - spec/lib/seatbelt/synthesizers/mongoid_spec.rb
150
+ - spec/lib/seatbelt/synthesizers/synthesizer_spec.rb
151
+ - spec/lib/seatbelt/tape_deck_spec.rb
152
+ - spec/lib/seatbelt/tapes/tape_spec.rb
153
+ - spec/lib/seatbelt/translator_spec.rb
154
+ - spec/spec_helper.rb
155
+ - spec/support/implementations/seatbelt_environment.rb
156
+ - spec/support/shared_examples/shared_api_class.rb
157
+ - spec/support/shared_examples/shared_collection_child.rb
158
+ - spec/support/worlds/eigenmethod_world.rb
159
+ homepage: ''
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.4.6
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: Define headers in your Ruby (we try to)
183
+ test_files:
184
+ - spec/lib/seatbelt/core/eigenmethod_spec.rb
185
+ - spec/lib/seatbelt/core/gate_spec.rb
186
+ - spec/lib/seatbelt/core/ghost_tunnel_spec.rb
187
+ - spec/lib/seatbelt/core/lookup_table_spec.rb
188
+ - spec/lib/seatbelt/core/pool_spec.rb
189
+ - spec/lib/seatbelt/core/proxy_spec.rb
190
+ - spec/lib/seatbelt/core/terminal_spec.rb
191
+ - spec/lib/seatbelt/document_spec.rb
192
+ - spec/lib/seatbelt/gate_config_spec.rb
193
+ - spec/lib/seatbelt/ghost_spec.rb
194
+ - spec/lib/seatbelt/synthesizers/document_spec.rb
195
+ - spec/lib/seatbelt/synthesizers/mongoid_spec.rb
196
+ - spec/lib/seatbelt/synthesizers/synthesizer_spec.rb
197
+ - spec/lib/seatbelt/tape_deck_spec.rb
198
+ - spec/lib/seatbelt/tapes/tape_spec.rb
199
+ - spec/lib/seatbelt/translator_spec.rb
200
+ - spec/spec_helper.rb
201
+ - spec/support/implementations/seatbelt_environment.rb
202
+ - spec/support/shared_examples/shared_api_class.rb
203
+ - spec/support/shared_examples/shared_collection_child.rb
204
+ - spec/support/worlds/eigenmethod_world.rb
205
+ has_rdoc: