sinatra-mongo-config 0.0.1
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.
- data/README.md +42 -0
- data/lib/sinatra/mongo_config.rb +33 -0
- metadata +101 -0
data/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
Sinatra-Mongo-Config
|
|
2
|
+
====================
|
|
3
|
+
|
|
4
|
+
A simple wrapper for instantiating a MongoDB connection in Sinatra
|
|
5
|
+
|
|
6
|
+
Installing
|
|
7
|
+
----------
|
|
8
|
+
|
|
9
|
+
gem install sinatra-mongo-config
|
|
10
|
+
|
|
11
|
+
Usage
|
|
12
|
+
-----
|
|
13
|
+
|
|
14
|
+
Set some properties so that a connection can be made to your MongoDB database. You then have access to a database object which represents your MongoDB database.
|
|
15
|
+
|
|
16
|
+
The complete list of parameters is:
|
|
17
|
+
|
|
18
|
+
:mongo_db
|
|
19
|
+
:mongo_host
|
|
20
|
+
:mongo_port
|
|
21
|
+
:mongo_user
|
|
22
|
+
:mongo_password
|
|
23
|
+
|
|
24
|
+
The only property you really need to set is mongo_db, everything else has sensible defaults for development.
|
|
25
|
+
|
|
26
|
+
Example
|
|
27
|
+
------
|
|
28
|
+
|
|
29
|
+
configure do
|
|
30
|
+
set :mongo_db, 'ethangunderson'
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
configure :production do
|
|
34
|
+
set :mongo_host, 'flame.local.mongohq.com'
|
|
35
|
+
set :mongo_user, 'foo'
|
|
36
|
+
set :mongo_password, 'bar'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
get '/blog' do
|
|
40
|
+
@posts = database['posts'].find()
|
|
41
|
+
haml :blog
|
|
42
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'sinatra/base'
|
|
2
|
+
require 'mongo'
|
|
3
|
+
|
|
4
|
+
module Sinatra
|
|
5
|
+
module MongoConfig
|
|
6
|
+
|
|
7
|
+
module Helpers
|
|
8
|
+
def database
|
|
9
|
+
@database ||= init_database
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
private
|
|
13
|
+
|
|
14
|
+
def init_database
|
|
15
|
+
db = Mongo::Connection.new(settings.mongo_host, settings.mongo_port).db(settings.mongo_db)
|
|
16
|
+
db.authenticate(settings.mongo_user, settings.mongo_password) if settings.mongo_user && settings.mongo_password
|
|
17
|
+
db
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def self.registered(app)
|
|
22
|
+
app.helpers MongoConfig::Helpers
|
|
23
|
+
|
|
24
|
+
app.set :mongo_host, 'localhost'
|
|
25
|
+
app.set :mongo_port, Mongo::Connection::DEFAULT_PORT
|
|
26
|
+
app.set :mongo_db, 'test'
|
|
27
|
+
app.set :mongo_user, nil
|
|
28
|
+
app.set :mongo_password, nil
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
register MongoConfig
|
|
33
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sinatra-mongo-config
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease: false
|
|
5
|
+
segments:
|
|
6
|
+
- 0
|
|
7
|
+
- 0
|
|
8
|
+
- 1
|
|
9
|
+
version: 0.0.1
|
|
10
|
+
platform: ruby
|
|
11
|
+
authors:
|
|
12
|
+
- Ethan Gunderson
|
|
13
|
+
autorequire:
|
|
14
|
+
bindir: bin
|
|
15
|
+
cert_chain: []
|
|
16
|
+
|
|
17
|
+
date: 2010-05-05 00:00:00 -05:00
|
|
18
|
+
default_executable:
|
|
19
|
+
dependencies:
|
|
20
|
+
- !ruby/object:Gem::Dependency
|
|
21
|
+
name: sinatra
|
|
22
|
+
prerelease: false
|
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
24
|
+
requirements:
|
|
25
|
+
- - ">="
|
|
26
|
+
- !ruby/object:Gem::Version
|
|
27
|
+
segments:
|
|
28
|
+
- 1
|
|
29
|
+
- 0
|
|
30
|
+
version: "1.0"
|
|
31
|
+
type: :runtime
|
|
32
|
+
version_requirements: *id001
|
|
33
|
+
- !ruby/object:Gem::Dependency
|
|
34
|
+
name: mongo
|
|
35
|
+
prerelease: false
|
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
segments:
|
|
41
|
+
- 1
|
|
42
|
+
- 0
|
|
43
|
+
version: "1.0"
|
|
44
|
+
type: :runtime
|
|
45
|
+
version_requirements: *id002
|
|
46
|
+
- !ruby/object:Gem::Dependency
|
|
47
|
+
name: bson_ext
|
|
48
|
+
prerelease: false
|
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
segments:
|
|
54
|
+
- 1
|
|
55
|
+
- 0
|
|
56
|
+
version: "1.0"
|
|
57
|
+
type: :runtime
|
|
58
|
+
version_requirements: *id003
|
|
59
|
+
description: A simple wrapper for instantiating a MongoDB connection in Sinatra
|
|
60
|
+
email: ethan@ethangunderson.com
|
|
61
|
+
executables: []
|
|
62
|
+
|
|
63
|
+
extensions: []
|
|
64
|
+
|
|
65
|
+
extra_rdoc_files: []
|
|
66
|
+
|
|
67
|
+
files:
|
|
68
|
+
- README.md
|
|
69
|
+
- lib/sinatra/mongo_config.rb
|
|
70
|
+
has_rdoc: true
|
|
71
|
+
homepage: http://github.com/ethangunderson/sinatra-mongo-config
|
|
72
|
+
licenses: []
|
|
73
|
+
|
|
74
|
+
post_install_message:
|
|
75
|
+
rdoc_options: []
|
|
76
|
+
|
|
77
|
+
require_paths:
|
|
78
|
+
- lib
|
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
segments:
|
|
84
|
+
- 0
|
|
85
|
+
version: "0"
|
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
|
+
requirements:
|
|
88
|
+
- - ">="
|
|
89
|
+
- !ruby/object:Gem::Version
|
|
90
|
+
segments:
|
|
91
|
+
- 0
|
|
92
|
+
version: "0"
|
|
93
|
+
requirements: []
|
|
94
|
+
|
|
95
|
+
rubyforge_project:
|
|
96
|
+
rubygems_version: 1.3.6
|
|
97
|
+
signing_key:
|
|
98
|
+
specification_version: 3
|
|
99
|
+
summary: A thin Mongo wrapper for Sinatra.
|
|
100
|
+
test_files: []
|
|
101
|
+
|