eldr 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +28 -0
  4. data/.rubocop_todo.yml +15 -0
  5. data/.travis.yml +3 -0
  6. data/DUCK.md +15 -0
  7. data/Gemfile +3 -0
  8. data/Gemfile.lock +89 -0
  9. data/LICENSE +20 -0
  10. data/README.md +876 -0
  11. data/Rakefile +9 -0
  12. data/TODOS +3 -0
  13. data/eldr.gemspec +36 -0
  14. data/examples/README.md +7 -0
  15. data/examples/action_objects.ru +28 -0
  16. data/examples/app.ru +75 -0
  17. data/examples/builder.ru +24 -0
  18. data/examples/custom_response.ru +23 -0
  19. data/examples/errors.ru +16 -0
  20. data/examples/hello_world.ru +8 -0
  21. data/examples/inheritance.ru +22 -0
  22. data/examples/multiple_apps.ru +30 -0
  23. data/examples/rails_style_routing.ru +14 -0
  24. data/examples/rendering_templates.ru +38 -0
  25. data/examples/views/cats.slim +1 -0
  26. data/lib/eldr/app.rb +146 -0
  27. data/lib/eldr/builder.rb +60 -0
  28. data/lib/eldr/configuration.rb +37 -0
  29. data/lib/eldr/matcher.rb +36 -0
  30. data/lib/eldr/recognizer.rb +35 -0
  31. data/lib/eldr/route.rb +92 -0
  32. data/lib/eldr/version.rb +3 -0
  33. data/lib/eldr.rb +1 -0
  34. data/spec/app_spec.rb +194 -0
  35. data/spec/builder_spec.rb +11 -0
  36. data/spec/configuration_spec.rb +29 -0
  37. data/spec/examples/action_objects_spec.rb +18 -0
  38. data/spec/examples/builder_spec.rb +16 -0
  39. data/spec/examples/custom_response_spec.rb +17 -0
  40. data/spec/examples/errors_spec.rb +18 -0
  41. data/spec/examples/example_app_spec.rb +98 -0
  42. data/spec/examples/hello_world_spec.rb +17 -0
  43. data/spec/examples/inheritance_spec.rb +23 -0
  44. data/spec/examples/multiple_apps_spec.rb +31 -0
  45. data/spec/examples/rails_style_routing_spec.rb +17 -0
  46. data/spec/examples/rendering_templates_spec.rb +26 -0
  47. data/spec/matcher_spec.rb +21 -0
  48. data/spec/readme_definitions.yml +28 -0
  49. data/spec/readme_spec.rb +117 -0
  50. data/spec/recognizer_spec.rb +32 -0
  51. data/spec/route_spec.rb +131 -0
  52. data/spec/spec_helper.rb +14 -0
  53. metadata +252 -0
@@ -0,0 +1,117 @@
1
+ require 'yaml'
2
+
3
+ describe 'README' do
4
+ let(:readme) do
5
+ readme = YAML.load_file(File.expand_path('./readme_definitions.yml', File.dirname(__FILE__)))
6
+ end
7
+
8
+ it 'has a hook' do
9
+ expect(readme['has_hook']).to eq true
10
+ end
11
+
12
+ it 'links to badges' do
13
+ expect(readme['links_to_badges']).to eq true
14
+ end
15
+
16
+ it 'has a simple example' do
17
+ expect(readme['has_simple_example']).to eq true
18
+ end
19
+
20
+ it 'shows that eldr apps are rack apps' do
21
+ expect(readme['are_rack_apps']).to eq true
22
+ end
23
+
24
+ it 'has installation instructions' do
25
+ expect(readme['installation_instructions']).to eq true
26
+ end
27
+
28
+ it 'has a features list' do
29
+ expect(readme['features_list']).to eq true
30
+ end
31
+
32
+ it 'has a quickstart section' do
33
+ expect(readme['has_quickstart']).to eq true
34
+ end
35
+
36
+ describe 'quickstart' do
37
+ it 'has a run down that goes from install, file, to booting' do
38
+ expect(readme['quickstart']['has_rundown']).to eq true
39
+ end
40
+
41
+ it 'shows how to render a template' do
42
+ expect(readme['quickstart']['templates']).to eq true
43
+ end
44
+
45
+ it 'shows how to do helpers' do
46
+ expect(readme['quickstart']['helpers']).to eq true
47
+ end
48
+
49
+ it 'shows how to do rails styling routing' do
50
+ expect(readme['quickstart']['rails_style_routing']).to eq true
51
+ end
52
+
53
+ it 'shows how to do rails style responses' do
54
+ expect(readme['quickstart']['rails_style_responses']).to eq true
55
+ end
56
+
57
+ it 'shows how to rails style requests' do
58
+ expect(readme['quickstart']['rails_style_requests']).to eq true
59
+ end
60
+
61
+ it 'shows how to do extensions' do
62
+ expect(readme['quickstart']['extensions']).to eq true
63
+ end
64
+
65
+ it 'shows how to use builder inside an app class' do
66
+ expect(readme['quickstart']['builder']).to eq true
67
+ end
68
+
69
+ it 'goes over redirects' do
70
+ expect(readme['quickstart']['redirects']).to eq true
71
+ end
72
+
73
+ describe 'handlers' do
74
+ it 'goes over handlers as just things that take a call' do
75
+ expect(readme['quickstart']['handlers']['call']).to eq true
76
+ end
77
+
78
+ it 'shows how we can use any object' do
79
+ expect(readme['quickstart']['handlers']['any_object']).to eq true
80
+ end
81
+
82
+ describe 'Action Objects' do
83
+ it 'shows how we can use action objects' do
84
+ expect(readme['quickstart']['handlers']['action_objects']).to eq true
85
+ end
86
+
87
+ it 'shows how we can use action objects in a controller' do
88
+ expect(readme['quickstart']['handlers']['action_objects_example']).to eq true
89
+ end
90
+ end
91
+ end
92
+
93
+ it 'has a section on testing' do
94
+ expect(readme['quickstart']['testing']).to eq true
95
+ end
96
+ end
97
+
98
+ it 'loop back around and show Eldr apps are just rack apps' do
99
+ expect(readme['has_rack_loop']).to eq true
100
+ end
101
+
102
+ it 'mention examples folder' do
103
+ expect(readme['mentions_examples_folder']).to eq true
104
+ end
105
+
106
+ it 'link to places to get help' do
107
+ expect(readme['has_help']).to eq true
108
+ end
109
+
110
+ it 'has a section on contributing' do
111
+ expect(readme['has_contributing']).to eq true
112
+ end
113
+
114
+ it 'has a license' do
115
+ expect(readme['has_license']).to eq true
116
+ end
117
+ end
@@ -0,0 +1,32 @@
1
+ describe Eldr::Recognizer do
2
+ describe '#call' do
3
+ let(:resp_proc) { proc { [200, {}, ['Hello Bob!']] } }
4
+ subject(:app) do
5
+ bob = Class.new(Eldr::App)
6
+ bob.get '/cats', resp_proc
7
+ bob
8
+ end
9
+
10
+ let(:recognizer) { Eldr::Recognizer.new(app.routes) }
11
+
12
+ context 'when there are matching routes' do
13
+ let(:env) do
14
+ Rack::MockRequest.env_for('/cats', {:method => :get})
15
+ end
16
+
17
+ it 'returns matching routes' do
18
+ expect(recognizer.call(env).length).to eq(1)
19
+ end
20
+ end
21
+
22
+ context 'when there are no matching routes' do
23
+ let(:env) do
24
+ Rack::MockRequest.env_for('/no-route-for-me', {:method => :get})
25
+ end
26
+
27
+ it 'raises a NotFound error' do
28
+ expect { recognizer.call(env) }.to raise_error
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,131 @@
1
+ class CatsHandler
2
+ def index(env)
3
+ 'cats'
4
+ end
5
+ end
6
+
7
+ class ActionHandler
8
+ def call(env)
9
+ 'action handled!'
10
+ end
11
+ end
12
+
13
+ describe Eldr::Route do
14
+ describe '.new' do
15
+ it 'returns a new instance' do
16
+ expect(Eldr::Route.new).to be_instance_of Eldr::Route
17
+ end
18
+
19
+ it 'takes options and sets them' do
20
+ route = Eldr::Route.new(options: { name: :cats })
21
+ expect(route.name).to eq(:cats)
22
+ end
23
+ end
24
+
25
+ describe '#response' do
26
+ let(:route) do
27
+ Eldr::Route.new(handler: proc { 'cats' })
28
+ end
29
+
30
+ it 'determines type of handler and calls it' do
31
+ expect(route.response({})).to eq('cats')
32
+ end
33
+ end
34
+
35
+ describe '#rails_style_response' do
36
+ let(:route) do
37
+ Eldr::Route.new(handler: 'CatsHandler#index')
38
+ end
39
+
40
+ it 'calls a handler using a string like Controller#action' do
41
+ expect(route.response({})).to eq('cats')
42
+ end
43
+ end
44
+
45
+ describe '#params' do
46
+ let(:route) do
47
+ Eldr::Route.new(path: '/cats/:id')
48
+ end
49
+
50
+ it 'returns splat parameters for a path string' do
51
+ expect(route.params('/cats/omalley')['id']).to eq('omalley')
52
+ end
53
+ end
54
+
55
+ describe '#call' do
56
+ context 'when #app is nil' do
57
+ let(:route) do
58
+ Eldr::Route.new(handler: proc { 'cats' })
59
+ end
60
+
61
+ it "still calls a route's handler" do
62
+ expect(route.call({})).to eq('cats')
63
+ end
64
+ end
65
+
66
+ context 'when handler is a proc' do
67
+ let(:route) do
68
+ Eldr::Route.new(handler: proc { @cats })
69
+ end
70
+
71
+ let(:app) do
72
+ class Bob < Eldr::App
73
+ attr_accessor :cats
74
+ end
75
+ bob = Bob._new()
76
+ bob.cats = 'cats'
77
+ bob
78
+ end
79
+
80
+ it 'calls it in the scope of the app instances and returns the response' do
81
+ expect(route.call({}, app: app)).to eq('cats')
82
+ end
83
+ end
84
+
85
+ context 'when handler is a string' do
86
+ let(:route) do
87
+ Eldr::Route.new(handler: 'CatsHandler#index')
88
+ end
89
+
90
+ it 'splits string into a controller name/method; and then calls it with env' do
91
+ expect(route.call({})).to eq('cats')
92
+ end
93
+ end
94
+
95
+ context 'when handler is an object' do
96
+ let(:route) do
97
+ Eldr::Route.new(handler: ActionHandler.new)
98
+ end
99
+
100
+ it 'calla the #call method of the object' do
101
+ expect(route.call({})).to eq('action handled!')
102
+ end
103
+ end
104
+
105
+ context 'when there are before filters' do
106
+ let(:route) do
107
+ Eldr::Route.new(handler: proc { 'cats' })
108
+ end
109
+
110
+ it 'calls the before filters' do
111
+ called = false
112
+ route.before_filters << proc { called = true }
113
+ route.call({})
114
+ expect(called).to eq(true)
115
+ end
116
+ end
117
+
118
+ context 'when there are after filters' do
119
+ let(:route) do
120
+ Eldr::Route.new(handler: proc { 'cats' })
121
+ end
122
+
123
+ it 'calls the before filters' do
124
+ called = false
125
+ route.after_filters << proc { called = true }
126
+ route.call({})
127
+ expect(called).to eq(true)
128
+ end
129
+ end
130
+ end
131
+ end
@@ -0,0 +1,14 @@
1
+ if ENV['COVERALLS_REPO_TOKEN']
2
+ require 'coveralls'
3
+ Coveralls.wear!
4
+ end
5
+
6
+ require 'rack/test'
7
+ require 'rack'
8
+ require_relative '../lib/eldr'
9
+
10
+ # Hardcode an instance into a global because rack-test likes to get too clever
11
+ RSpec.configure do |config|
12
+ config.include Rack::Test::Methods
13
+ config.pattern = '**{,/*/**}/*_spec.rb'
14
+ end
metadata ADDED
@@ -0,0 +1,252 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eldr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - K-2052
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mustermann
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.4.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: fast_blank
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.0.2
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 10.4.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 10.4.2
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '='
88
+ - !ruby/object:Gem::Version
89
+ version: 3.1.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '='
95
+ - !ruby/object:Gem::Version
96
+ version: 3.1.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.28.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.28.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: rack-test
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.6.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 0.6.2
125
+ - !ruby/object:Gem::Dependency
126
+ name: tilt
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 2.0.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 2.0.1
139
+ - !ruby/object:Gem::Dependency
140
+ name: slim
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 3.0.1
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 3.0.1
153
+ - !ruby/object:Gem::Dependency
154
+ name: coveralls
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: '0.7'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: '0.7'
167
+ description: |-
168
+ A minimal framework that lights a fire in your development.
169
+ Built close to Rack and the metal.
170
+ email:
171
+ - k@2052.me
172
+ executables: []
173
+ extensions: []
174
+ extra_rdoc_files: []
175
+ files:
176
+ - ".rspec"
177
+ - ".rubocop.yml"
178
+ - ".rubocop_todo.yml"
179
+ - ".travis.yml"
180
+ - DUCK.md
181
+ - Gemfile
182
+ - Gemfile.lock
183
+ - LICENSE
184
+ - README.md
185
+ - Rakefile
186
+ - TODOS
187
+ - eldr.gemspec
188
+ - examples/README.md
189
+ - examples/action_objects.ru
190
+ - examples/app.ru
191
+ - examples/builder.ru
192
+ - examples/custom_response.ru
193
+ - examples/errors.ru
194
+ - examples/hello_world.ru
195
+ - examples/inheritance.ru
196
+ - examples/multiple_apps.ru
197
+ - examples/rails_style_routing.ru
198
+ - examples/rendering_templates.ru
199
+ - examples/views/cats.slim
200
+ - lib/eldr.rb
201
+ - lib/eldr/app.rb
202
+ - lib/eldr/builder.rb
203
+ - lib/eldr/configuration.rb
204
+ - lib/eldr/matcher.rb
205
+ - lib/eldr/recognizer.rb
206
+ - lib/eldr/route.rb
207
+ - lib/eldr/version.rb
208
+ - spec/app_spec.rb
209
+ - spec/builder_spec.rb
210
+ - spec/configuration_spec.rb
211
+ - spec/examples/action_objects_spec.rb
212
+ - spec/examples/builder_spec.rb
213
+ - spec/examples/custom_response_spec.rb
214
+ - spec/examples/errors_spec.rb
215
+ - spec/examples/example_app_spec.rb
216
+ - spec/examples/hello_world_spec.rb
217
+ - spec/examples/inheritance_spec.rb
218
+ - spec/examples/multiple_apps_spec.rb
219
+ - spec/examples/rails_style_routing_spec.rb
220
+ - spec/examples/rendering_templates_spec.rb
221
+ - spec/matcher_spec.rb
222
+ - spec/readme_definitions.yml
223
+ - spec/readme_spec.rb
224
+ - spec/recognizer_spec.rb
225
+ - spec/route_spec.rb
226
+ - spec/spec_helper.rb
227
+ homepage: https://github.com/eldr-rb/eldr
228
+ licenses:
229
+ - MIT
230
+ metadata: {}
231
+ post_install_message:
232
+ rdoc_options: []
233
+ require_paths:
234
+ - lib
235
+ required_ruby_version: !ruby/object:Gem::Requirement
236
+ requirements:
237
+ - - "~>"
238
+ - !ruby/object:Gem::Version
239
+ version: '2.0'
240
+ required_rubygems_version: !ruby/object:Gem::Requirement
241
+ requirements:
242
+ - - "~>"
243
+ - !ruby/object:Gem::Version
244
+ version: 1.3.6
245
+ requirements: []
246
+ rubyforge_project: eldr
247
+ rubygems_version: 2.2.2
248
+ signing_key:
249
+ specification_version: 4
250
+ summary: A minimal framework that lights a fire in your development
251
+ test_files: []
252
+ has_rdoc: