dependor-sinatra 0.0.1 → 0.0.2

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.
@@ -15,3 +15,9 @@ end
15
15
  get "/hello/:name" do |greeter|
16
16
  greeter.greet
17
17
  end
18
+
19
+ without_dependor do
20
+ get %r{/bye/(\w+)} do |name|
21
+ "bye #{name}"
22
+ end
23
+ end
@@ -3,6 +3,7 @@ require "dependor"
3
3
 
4
4
  require "dependor-sinatra/block_wrapper"
5
5
  require "dependor-sinatra/enabler"
6
+ require "dependor-sinatra/without_dependor"
6
7
  require "dependor-sinatra/has_injector"
7
8
  require "dependor-sinatra/objects"
8
9
  require "dependor-sinatra/version"
@@ -1,13 +1,15 @@
1
1
  module Dependor
2
2
  module Sinatra
3
3
  module Enabler
4
- def enable_dependor(method)
4
+ def enable_dependor_for_method(method)
5
5
  without_dependor = :"#{method}_without_dependor"
6
6
 
7
7
  # the only way to alias a private method
8
8
  instance_eval("alias #{without_dependor} #{method}")
9
9
 
10
10
  define_singleton_method(method) do |*args, &block|
11
+ return __send__(without_dependor, *args, &block) if dependor_disabled?
12
+
11
13
  wrapped_block = Dependor::Sinatra::BlockWrapper.wrap(block)
12
14
  __send__(without_dependor, *args) do
13
15
  instance_eval(&wrapped_block)
@@ -1,9 +1,11 @@
1
1
  class Sinatra::Base
2
2
  include Dependor::Sinatra::HasInjector
3
3
  extend Dependor::Sinatra::Enabler
4
- enable_dependor :route
5
- enable_dependor :add_filter
6
- enable_dependor :condition
4
+ extend Dependor::Sinatra::WithoutDependor
5
+ enable_dependor_for_method :route
6
+ enable_dependor_for_method :add_filter
7
+ enable_dependor_for_method :condition
7
8
  end
8
9
 
9
10
  Sinatra::Delegator.delegate :injector
11
+ Sinatra::Delegator.delegate :without_dependor
@@ -1,5 +1,5 @@
1
1
  module Dependor
2
2
  module Sinatra
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -0,0 +1,23 @@
1
+ module Dependor
2
+ module Sinatra
3
+ module WithoutDependor
4
+ def disable_dependor
5
+ @dependor_disabled = true
6
+ end
7
+
8
+ def enable_dependor
9
+ @dependor_disabled = false
10
+ end
11
+
12
+ def dependor_disabled?
13
+ @dependor_disabled
14
+ end
15
+
16
+ def without_dependor(&block)
17
+ disable_dependor
18
+ block.call
19
+ enable_dependor
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ class SomeDependency
4
+ def foo(str)
5
+ "foo - #{str}"
6
+ end
7
+ end
8
+
9
+ class AppWithDependencyInjectionDisabled < Sinatra::Base
10
+ set :environment, :test
11
+
12
+ without_dependor do
13
+ get %r{/bye/(\w+)} do |name|
14
+ "bye - #{name}"
15
+ end
16
+ end
17
+
18
+ get %r{/hello/(\w+)} do |some_dependency|
19
+ name = params[:captures].first
20
+ some_dependency.foo(name)
21
+ end
22
+ end
23
+
24
+ describe "Disabling dependency injection using without_dependor" do
25
+ let(:app) { AppWithDependencyInjectionDisabled }
26
+
27
+ it "injects the actions that are outside of without_dependor block" do
28
+ get "/hello/adam"
29
+
30
+ last_response.body.should == "foo - adam"
31
+ end
32
+
33
+ it "does not try to inject dependencies within actions defined in without_dependor block" do
34
+ get "/bye/adam"
35
+
36
+ last_response.body.should == "bye - adam"
37
+ end
38
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependor-sinatra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-14 00:00:00.000000000 Z
12
+ date: 2013-02-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dependor
@@ -211,9 +211,11 @@ files:
211
211
  - lib/dependor-sinatra/monkey_patches.rb
212
212
  - lib/dependor-sinatra/objects.rb
213
213
  - lib/dependor-sinatra/version.rb
214
+ - lib/dependor-sinatra/without_dependor.rb
214
215
  - spec/integration/before_and_after_filters_spec.rb
215
216
  - spec/integration/conditions_spec.rb
216
217
  - spec/integration/custom_injector_spec.rb
218
+ - spec/integration/disabling_dependor_spec.rb
217
219
  - spec/integration/injecting_sinatra_provided_data_spec.rb
218
220
  - spec/spec_helper.rb
219
221
  homepage: https://github.com/psyho/dependor-sinatra
@@ -230,7 +232,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
230
232
  version: '0'
231
233
  segments:
232
234
  - 0
233
- hash: 206932367
235
+ hash: 2355277459473621292
234
236
  required_rubygems_version: !ruby/object:Gem::Requirement
235
237
  none: false
236
238
  requirements:
@@ -239,10 +241,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
239
241
  version: '0'
240
242
  segments:
241
243
  - 0
242
- hash: 206932367
244
+ hash: 2355277459473621292
243
245
  requirements: []
244
246
  rubyforge_project:
245
- rubygems_version: 1.8.24
247
+ rubygems_version: 1.8.25
246
248
  signing_key:
247
249
  specification_version: 3
248
250
  summary: An extension to Sinatra enabling dependency injection
@@ -250,5 +252,6 @@ test_files:
250
252
  - spec/integration/before_and_after_filters_spec.rb
251
253
  - spec/integration/conditions_spec.rb
252
254
  - spec/integration/custom_injector_spec.rb
255
+ - spec/integration/disabling_dependor_spec.rb
253
256
  - spec/integration/injecting_sinatra_provided_data_spec.rb
254
257
  - spec/spec_helper.rb