sinatra-indextank 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/Gemfile +2 -0
- data/README.textile +26 -0
- data/Rakefile +10 -0
- data/lib/sinatra/indextank.rb +30 -0
- data/sinatra-indextank.gemspec +21 -0
- data/spec/sinatra-indextank_spec.rb +64 -0
- data/spec/spec_helper.rb +4 -0
- metadata +100 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/README.textile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
h1. sinatra-indextank
|
2
|
+
|
3
|
+
Extends Sinatra with an extension method for dealing with IndexTank.
|
4
|
+
|
5
|
+
h2. Installation
|
6
|
+
|
7
|
+
Install it with gem:
|
8
|
+
|
9
|
+
@$ gem install sinatra-indextank@
|
10
|
+
|
11
|
+
Now we can use it an example application.
|
12
|
+
|
13
|
+
<pre><code>require 'sinatra'
|
14
|
+
require 'sinatra/indextank'
|
15
|
+
|
16
|
+
# Obtain an IndexTank client using your private api url
|
17
|
+
# Or, specify the INDEXTANK_API_URL as an environment variable
|
18
|
+
set :indextank, 'http://_your_private_api_url@api.indextank.com'
|
19
|
+
|
20
|
+
# At this point, you can access the IndexTank::Client object using the 'indextank' helper:
|
21
|
+
|
22
|
+
get '/search' do
|
23
|
+
@results = indextank.indexes('idx').search(params[:q])
|
24
|
+
end
|
25
|
+
</code>
|
26
|
+
</pre>
|
data/Rakefile
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'indextank'
|
3
|
+
|
4
|
+
module Sinatra
|
5
|
+
module IndexTankHelper
|
6
|
+
def indextank
|
7
|
+
options.indextank
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
module IndexTankExtension
|
12
|
+
def indextank=(url)
|
13
|
+
@indextank = nil
|
14
|
+
set :indextank_url, url
|
15
|
+
indextank
|
16
|
+
end
|
17
|
+
|
18
|
+
def indextank
|
19
|
+
synchronize { @indextank ||= IndexTank::Client.new(indextank_url) }
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
def self.registered(app)
|
24
|
+
app.set :indextank_url, ENV['INDEXTANK_API_URL']
|
25
|
+
app.helpers IndexTankHelper
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
register IndexTankExtension
|
30
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "sinatra-indextank"
|
5
|
+
s.version = "1.0.0"
|
6
|
+
s.authors = ["Brian Ryckbost"]
|
7
|
+
s.email = ["brian@collectiveidea.com"]
|
8
|
+
s.homepage = ""
|
9
|
+
s.summary = %q{A simple extension to sinatra for using IndexTank}
|
10
|
+
s.description = %q{A simple extension to sinatra for using IndexTank}
|
11
|
+
|
12
|
+
s.files = `git ls-files`.split("\n")
|
13
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
|
17
|
+
s.add_runtime_dependency "sinatra"
|
18
|
+
s.add_runtime_dependency "indextank"
|
19
|
+
s.add_development_dependency "rspec"
|
20
|
+
s.add_development_dependency "rack-test"
|
21
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Sinatra::IndexTankExtension" do
|
4
|
+
before(:each) do
|
5
|
+
@app = Sinatra.new
|
6
|
+
@app.register Sinatra::IndexTankExtension
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#indextank" do
|
10
|
+
before do
|
11
|
+
@app.indextank = "http://:private_api@private.api.indextank.com"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "returns an IndexTank client" do
|
15
|
+
@app.indextank.should be_kind_of(IndexTank::Client)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "sets the indextank_url" do
|
19
|
+
@app.indextank_url.should == "http://:private_api@private.api.indextank.com"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#indextank=" do
|
24
|
+
before(:each) do
|
25
|
+
@indextank_url = "http://:public_api@public.api.indextank.com"
|
26
|
+
@app.stub!(:indextank).and_return(mock('indextank'))
|
27
|
+
end
|
28
|
+
|
29
|
+
it "sets indextank_url" do
|
30
|
+
@app.indextank = @indextank_url
|
31
|
+
@app.indextank_url.should == @indextank_url
|
32
|
+
end
|
33
|
+
|
34
|
+
it "calls #indextank to instantiate an IndexTank::Client" do
|
35
|
+
@app.should_receive(:indextank)
|
36
|
+
@app.indextank = @indextank_url
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "register the extension" do
|
42
|
+
before do
|
43
|
+
@app = Sinatra.new
|
44
|
+
end
|
45
|
+
|
46
|
+
it "sets indextank_url from the environment variable" do
|
47
|
+
@indextank_url = "http://:public_api@public.api.indextank.com"
|
48
|
+
ENV['INDEXTANK_API_URL'] = @indextank_url
|
49
|
+
@app.register(Sinatra::IndexTankExtension)
|
50
|
+
|
51
|
+
@app.indextank_url.should == @indextank_url
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "Sinatra::IndexTankHelper" do
|
56
|
+
before do
|
57
|
+
@app = Sinatra.new
|
58
|
+
end
|
59
|
+
|
60
|
+
it "registers the helpers" do
|
61
|
+
@app.should_receive(:helpers).with(Sinatra::IndexTankHelper)
|
62
|
+
@app.register(Sinatra::IndexTankExtension)
|
63
|
+
end
|
64
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sinatra-indextank
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brian Ryckbost
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-06 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sinatra
|
16
|
+
requirement: &70229850385780 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70229850385780
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: indextank
|
27
|
+
requirement: &70229850385320 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70229850385320
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &70229850384800 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70229850384800
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rack-test
|
49
|
+
requirement: &70229850384260 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70229850384260
|
58
|
+
description: A simple extension to sinatra for using IndexTank
|
59
|
+
email:
|
60
|
+
- brian@collectiveidea.com
|
61
|
+
executables: []
|
62
|
+
extensions: []
|
63
|
+
extra_rdoc_files: []
|
64
|
+
files:
|
65
|
+
- .gitignore
|
66
|
+
- .rspec
|
67
|
+
- Gemfile
|
68
|
+
- README.textile
|
69
|
+
- Rakefile
|
70
|
+
- lib/sinatra/indextank.rb
|
71
|
+
- sinatra-indextank.gemspec
|
72
|
+
- spec/sinatra-indextank_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
homepage: ''
|
75
|
+
licenses: []
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.8.11
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: A simple extension to sinatra for using IndexTank
|
98
|
+
test_files:
|
99
|
+
- spec/sinatra-indextank_spec.rb
|
100
|
+
- spec/spec_helper.rb
|