sinatra-extension 0.5.0 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- metadata +31 -125
- data/LICENSE +0 -27
- data/README.md +0 -41
- data/lib/sinatra/extension.rb +0 -84
- data/spec/sinatra/extension_spec.rb +0 -88
- data/spec/spec_helper.rb +0 -2
metadata
CHANGED
@@ -1,149 +1,55 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-extension
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 5
|
9
|
-
- 0
|
10
|
-
version: 0.5.0
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
prerelease:
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Konstantin Haase
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
name: monkey-lib
|
23
|
-
prerelease: false
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
hash: 11
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
- 5
|
33
|
-
- 0
|
34
|
-
version: 0.5.0
|
35
|
-
type: :runtime
|
36
|
-
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: sinatra-sugar
|
39
|
-
prerelease: false
|
40
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
12
|
+
date: 2011-10-28 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra-contrib
|
16
|
+
requirement: &2158670240 !ruby/object:Gem::Requirement
|
41
17
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
segments:
|
47
|
-
- 0
|
48
|
-
- 5
|
49
|
-
- 0
|
50
|
-
version: 0.5.0
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
51
22
|
type: :runtime
|
52
|
-
version_requirements: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: sinatra-test-helper
|
55
23
|
prerelease: false
|
56
|
-
|
57
|
-
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
hash: 11
|
62
|
-
segments:
|
63
|
-
- 0
|
64
|
-
- 5
|
65
|
-
- 0
|
66
|
-
version: 0.5.0
|
67
|
-
type: :development
|
68
|
-
version_requirements: *id003
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: sinatra
|
71
|
-
prerelease: false
|
72
|
-
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ~>
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
hash: 15
|
78
|
-
segments:
|
79
|
-
- 1
|
80
|
-
- 0
|
81
|
-
version: "1.0"
|
82
|
-
type: :runtime
|
83
|
-
version_requirements: *id004
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: rspec
|
86
|
-
prerelease: false
|
87
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
88
|
-
none: false
|
89
|
-
requirements:
|
90
|
-
- - ">="
|
91
|
-
- !ruby/object:Gem::Version
|
92
|
-
hash: 27
|
93
|
-
segments:
|
94
|
-
- 1
|
95
|
-
- 3
|
96
|
-
- 0
|
97
|
-
version: 1.3.0
|
98
|
-
type: :development
|
99
|
-
version_requirements: *id005
|
100
|
-
description: Mixin to ease Sinatra extension development (part of BigBand).
|
24
|
+
version_requirements: *2158670240
|
25
|
+
description: ! 'Dummy gem, sinatra-extension is now part of sinatra-contrib: http://www.sinatrarb.com/contrib/'
|
101
26
|
email: konstantin.mailinglists@googlemail.com
|
102
27
|
executables: []
|
103
|
-
|
104
28
|
extensions: []
|
105
|
-
|
106
29
|
extra_rdoc_files: []
|
107
|
-
|
108
|
-
|
109
|
-
- lib/sinatra/extension.rb
|
110
|
-
- spec/sinatra/extension_spec.rb
|
111
|
-
- spec/spec_helper.rb
|
112
|
-
- README.md
|
113
|
-
- LICENSE
|
114
|
-
has_rdoc: yard
|
115
|
-
homepage: http://github.com/rkh/sinatra-extension
|
30
|
+
files: []
|
31
|
+
homepage: http://github.com/sinatra/sinatra-contrib
|
116
32
|
licenses: []
|
117
|
-
|
118
33
|
post_install_message:
|
119
34
|
rdoc_options: []
|
120
|
-
|
121
|
-
require_paths:
|
35
|
+
require_paths:
|
122
36
|
- lib
|
123
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
38
|
none: false
|
125
|
-
requirements:
|
126
|
-
- -
|
127
|
-
- !ruby/object:Gem::Version
|
128
|
-
|
129
|
-
|
130
|
-
- 0
|
131
|
-
version: "0"
|
132
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
44
|
none: false
|
134
|
-
requirements:
|
135
|
-
- -
|
136
|
-
- !ruby/object:Gem::Version
|
137
|
-
|
138
|
-
segments:
|
139
|
-
- 0
|
140
|
-
version: "0"
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
141
49
|
requirements: []
|
142
|
-
|
143
50
|
rubyforge_project:
|
144
|
-
rubygems_version: 1.
|
51
|
+
rubygems_version: 1.8.10
|
145
52
|
signing_key:
|
146
53
|
specification_version: 3
|
147
|
-
summary:
|
54
|
+
summary: Dummy gem, sinatra-extension is now part of sinatra-contrib.
|
148
55
|
test_files: []
|
149
|
-
|
data/LICENSE
DELETED
@@ -1,27 +0,0 @@
|
|
1
|
-
copyright (c) 2010 Konstantin Haase. All rights reserved.
|
2
|
-
|
3
|
-
Developed by: Konstantin Haase
|
4
|
-
http://github.com/rkh/big_band
|
5
|
-
|
6
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
-
of this software and associated documentation files (the "Software"), to
|
8
|
-
deal with the Software without restriction, including without limitation the
|
9
|
-
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
10
|
-
sell copies of the Software, and to permit persons to whom the Software is
|
11
|
-
furnished to do so, subject to the following conditions:
|
12
|
-
1. Redistributions of source code must retain the above copyright notice,
|
13
|
-
this list of conditions and the following disclaimers.
|
14
|
-
2. Redistributions in binary form must reproduce the above copyright
|
15
|
-
notice, this list of conditions and the following disclaimers in the
|
16
|
-
documentation and/or other materials provided with the distribution.
|
17
|
-
3. Neither the name of Konstantin Haase, nor the names of other contributors
|
18
|
-
may be used to endorse or promote products derived from this Software without
|
19
|
-
specific prior written permission.
|
20
|
-
|
21
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
22
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
23
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
24
|
-
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
25
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
26
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
27
|
-
WITH THE SOFTWARE.
|
data/README.md
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
Sinatra::Extension
|
2
|
-
==================
|
3
|
-
|
4
|
-
Mixin to ease [Sinatra](http://sinatrarb.com) extension development.
|
5
|
-
|
6
|
-
BigBand
|
7
|
-
-------
|
8
|
-
|
9
|
-
Sinatra::Extension is part of the [BigBand](http://github.com/rkh/big_band) stack.
|
10
|
-
Check it out if you are looking for other fancy Sinatra extensions.
|
11
|
-
|
12
|
-
Installation
|
13
|
-
------------
|
14
|
-
|
15
|
-
gem install sinatra-extension
|
16
|
-
|
17
|
-
Example
|
18
|
-
-------
|
19
|
-
|
20
|
-
module MyFancyExtension
|
21
|
-
extend Sinatra::Extension
|
22
|
-
|
23
|
-
enable :session
|
24
|
-
|
25
|
-
get '/foo' do
|
26
|
-
"bar"
|
27
|
-
end
|
28
|
-
|
29
|
-
# there also is on_set and on_disable
|
30
|
-
on_enable :fancy_mode do
|
31
|
-
use VeryFancyMiddleware
|
32
|
-
get '/fancy' do
|
33
|
-
"fancy!"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class MyApp < Sinatra::Base
|
39
|
-
register MyFancyExtension
|
40
|
-
enable :fancy_mode
|
41
|
-
end
|
data/lib/sinatra/extension.rb
DELETED
@@ -1,84 +0,0 @@
|
|
1
|
-
require 'sinatra/base'
|
2
|
-
require 'sinatra/sugar'
|
3
|
-
require 'monkey-lib'
|
4
|
-
|
5
|
-
module Sinatra
|
6
|
-
module Delegator
|
7
|
-
def self.delegate(*methods)
|
8
|
-
methods.each do |method_name|
|
9
|
-
eval <<-RUBY, binding, '(__DELEGATE__)', 1
|
10
|
-
def #{method_name}(*args, &b) sinatra_application.send(#{method_name.inspect}, *args, &b) end
|
11
|
-
private #{method_name.inspect}
|
12
|
-
RUBY
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
delegate(*private_instance_methods(false))
|
17
|
-
|
18
|
-
def sinatra_application
|
19
|
-
::Sinatra::Application
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
module Extension
|
24
|
-
BasicObject = Object unless defined? BasicObject
|
25
|
-
class MethodRecorder < BasicObject
|
26
|
-
def initialize(list) @calls = list end
|
27
|
-
def method_missing(*a, &b) @calls << [a, b] end
|
28
|
-
end
|
29
|
-
|
30
|
-
include Delegator
|
31
|
-
|
32
|
-
def method_calls
|
33
|
-
@method_calls ||= []
|
34
|
-
end
|
35
|
-
|
36
|
-
def register_hooks
|
37
|
-
@register_hooks ||= []
|
38
|
-
end
|
39
|
-
|
40
|
-
def on_register(&block)
|
41
|
-
register_hooks << block
|
42
|
-
end
|
43
|
-
|
44
|
-
def on_set(option, default_value = nil, &block)
|
45
|
-
mod = Module.new
|
46
|
-
mod.extend Sinatra::Extension
|
47
|
-
define_method(option) { default_value }
|
48
|
-
define_method("#{option}?") { !!__send__(option) }
|
49
|
-
define_method("#{option}=") do |value|
|
50
|
-
metadef(option) { value }
|
51
|
-
metadef("#{option}?") { !!value }
|
52
|
-
instance_yield block
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
def on_disable(option, &block)
|
57
|
-
on_set(option, true) { instance_yield block unless __send__ option }
|
58
|
-
end
|
59
|
-
|
60
|
-
def on_enable(option, &block)
|
61
|
-
on_set(option, false) { instance_yield block if __send__ option }
|
62
|
-
end
|
63
|
-
|
64
|
-
def register(*extensions)
|
65
|
-
on_register { register(*extensions) }
|
66
|
-
end
|
67
|
-
|
68
|
-
def configure(*args, &block)
|
69
|
-
on_register do
|
70
|
-
configure(*args) { |klass| klass.instance_yield block }
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def registered(klass)
|
75
|
-
register Sinatra::Sugar
|
76
|
-
method_calls.each { |a,b| klass.__send__(*a, &b) }
|
77
|
-
register_hooks.each { |hook| klass.instance_yield hook }
|
78
|
-
end
|
79
|
-
|
80
|
-
def sinatra_application
|
81
|
-
@sinatra_application ||= MethodRecorder.new method_calls
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
@@ -1,88 +0,0 @@
|
|
1
|
-
require File.expand_path("../../spec_helper", __FILE__)
|
2
|
-
|
3
|
-
module Sinatra
|
4
|
-
module OtherExtension
|
5
|
-
end
|
6
|
-
|
7
|
-
module ExampleExtension
|
8
|
-
extend Sinatra::Extension
|
9
|
-
register OtherExtension
|
10
|
-
|
11
|
-
%w[get put post delete].each { |verb| __send__(verb, '/foo') { 'bar' } }
|
12
|
-
|
13
|
-
configure(:test) { set :foo, 42 }
|
14
|
-
configure(:development) { set :foo, 'oh no' }
|
15
|
-
|
16
|
-
on_register do
|
17
|
-
set :bar,:blah
|
18
|
-
end
|
19
|
-
|
20
|
-
helpers do
|
21
|
-
def foo(value) value end
|
22
|
-
end
|
23
|
-
|
24
|
-
set :counter, 0
|
25
|
-
on_set(:trigger) { set :counter, counter + 1 }
|
26
|
-
|
27
|
-
on_enable :special_foo do
|
28
|
-
helpers do
|
29
|
-
def foo(value) 42 end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
describe Sinatra::Extension do
|
36
|
-
before { app :ExampleExtension }
|
37
|
-
it_should_behave_like 'sinatra'
|
38
|
-
|
39
|
-
it 'should forward register correctly' do
|
40
|
-
app.should be_a(Sinatra::OtherExtension)
|
41
|
-
end
|
42
|
-
|
43
|
-
%w[head get put post delete].each do |verb|
|
44
|
-
it "should forward #{verb} correctly" do
|
45
|
-
browse_route(verb, '/foo').should be_ok
|
46
|
-
last_response.body.should == 'bar' unless verb == 'head'
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should forward configure correctly" do
|
51
|
-
app.should be_test # just to be sure
|
52
|
-
app.foo.should == 42
|
53
|
-
end
|
54
|
-
|
55
|
-
it "should trigger on_register" do
|
56
|
-
app.bar.should == :blah
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should forward helpers correctly" do
|
60
|
-
app.new.foo(10).should == 10
|
61
|
-
end
|
62
|
-
|
63
|
-
it "should trigger on_set block" do
|
64
|
-
app.set :counter, 0
|
65
|
-
app.counter.should == 0
|
66
|
-
app.enable :trigger
|
67
|
-
app.counter.should == 1
|
68
|
-
app.disable :trigger
|
69
|
-
app.counter.should == 2
|
70
|
-
app.set :trigger, :foo
|
71
|
-
app.counter.should == 3
|
72
|
-
app.trigger = 42
|
73
|
-
app.counter.should == 4
|
74
|
-
end
|
75
|
-
|
76
|
-
it "should apply on_enable blocks only if given option has been enabled" do
|
77
|
-
app.should_not be_special_foo
|
78
|
-
app.special_foo.should be_false
|
79
|
-
app.new.foo(10).should == 10
|
80
|
-
app.disable :special_foo
|
81
|
-
app.should_not be_special_foo
|
82
|
-
app.special_foo.should be_false
|
83
|
-
app.new.foo(10).should == 10
|
84
|
-
app.enable :special_foo
|
85
|
-
app.should be_special_foo
|
86
|
-
app.new.foo(10).should == 42
|
87
|
-
end
|
88
|
-
end
|
data/spec/spec_helper.rb
DELETED