mongoid-simplify 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mongoid-simplify.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Sascha Wessel
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # Mongoid::Simplify
2
+
3
+ mongoid-simply is a dumb little monkey-patch, packaged into an gem, to restore good old functionality from mongoid 2 in mongoid 3.x
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mongoid-simplify'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mongoid-simplify
18
+
19
+ ## Usage
20
+
21
+ In mongoid 2.x there was an an method called `use`, which took an plain URI to your mongodb instance. In mongoid 3.x this functionality disappeared and the new way was configuring mongoid through an mongoid.yml file. I don't liked this approach, so I took the initiative and built this little gem.
22
+
23
+ Mongoid.use("mongodb://localhost:27017/database")
24
+
25
+ This sets the default session to the given mongodb instance and the database.
26
+
27
+ You may ask yourself: Nice, but what's with clustering?
28
+ I even thought about this and came around with this approach:
29
+
30
+ Mongoid.use(:default => "mongodb://localhost:27017/database")
31
+
32
+
33
+ Why I don't have forked mongoid and created an pull request:
34
+ My spare time is limited and I don't wanted to discuss this with the whole world. I just needed that functionality back, so I hacked it together, wrote some test cases and packaged it into an gem.
35
+
36
+ ## Contributing
37
+
38
+ 1. Fork it
39
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
40
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
41
+ 4. Push to the branch (`git push origin my-new-feature`)
42
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require "rake/testtask"
4
+ require "yard"
5
+
6
+ desc "generate documentation"
7
+ YARD::Rake::YardocTask.new do |task|
8
+ task.files << 'lib/**/*.rb'
9
+ end
10
+
11
+ desc "run the minitest specs"
12
+ Rake::TestTask.new(:spec) do |task|
13
+ task.libs << "spec"
14
+ task.test_files = FileList["spec/**/*_spec.rb"]
15
+ end
16
+
17
+ task :default => [:spec, :build, :yard]
@@ -0,0 +1,37 @@
1
+ module Mongoid::Simplify::Connection
2
+
3
+ #
4
+ # In mongoid >= 3 the methods for connecting changed into something to complex and to
5
+ # complicated. So I reimplemented this way of connecting with an plain URI.
6
+ #
7
+ # @example set the default session
8
+ # Mongoid.use("mongodb://localhost:27017/database")
9
+ #
10
+ def use(*args)
11
+ args.flatten.each do |arg|
12
+ if arg.kind_of? String
13
+ use_session(:default, arg)
14
+ elsif arg.kind_of? Hash
15
+ arg.each do |name, uri|
16
+ use_session(name.to_sym, uri)
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ private
23
+ def use_session(name, db_uri)
24
+ uri = URI.parse(db_uri)
25
+ sessions = Mongoid::Config.sessions
26
+ sessions[name.to_sym] = { database: mongodb_database(uri), hosts: [ mongodb_host(uri) ] }
27
+ end
28
+
29
+ def mongodb_host(uri)
30
+ "#{uri.host}:#{uri.port}"
31
+ end
32
+
33
+ def mongodb_database(uri)
34
+ uri.path.delete("/")
35
+ end
36
+
37
+ end
@@ -0,0 +1,5 @@
1
+ module Mongoid
2
+ module Simplify
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ require "mongoid-simplify/version"
2
+ require "mongoid-simplify/connection"
3
+ module Mongoid
4
+ extend Mongoid::Simplify::Connection
5
+
6
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/mongoid-simplify/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Sascha Wessel"]
6
+ gem.email = ["swessel@gr4yweb.de"]
7
+ gem.description = %q{makes it simple again to connect to mongodb with mongoid}
8
+ gem.summary = %q{makes it simple again to connect to mongodb with mongoid}
9
+ gem.homepage = "http://github.com/gr4y/mongoid-simplify"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "mongoid-simplify"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Mongoid::Simplify::VERSION
17
+
18
+ # development
19
+ gem.add_development_dependency "yard", "~> 0.8.2.1"
20
+ gem.add_development_dependency "minitest", "~> 3.3.0"
21
+ gem.add_development_dependency "redcarpet"
22
+
23
+ # runtime
24
+ gem.add_dependency "mongoid", "~> 3.0.5"
25
+
26
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ MASTER_URI = "mongodb://localhost:27017/simplify_master"
4
+ SLAVE_URI = "mongodb://localhost:27017/simplify_slave"
5
+
6
+ describe Mongoid::Simplify::Connection do
7
+
8
+ describe "#use" do
9
+
10
+ describe "when passed an uri as an string" do
11
+
12
+ before do
13
+ Mongoid.use(MASTER_URI)
14
+ end
15
+
16
+ it "should have some sessions configured" do
17
+ Mongoid::Config.sessions.wont_be_nil
18
+ Mongoid::Config.sessions.wont_be_empty
19
+ end
20
+
21
+ it "should have an default session configured" do
22
+ Mongoid::Config.sessions.has_key?(:default).must_equal true
23
+ end
24
+
25
+ it "shouldn't have an session named slave configured" do
26
+ Mongoid::Config.sessions.has_key?(:slave).must_equal false
27
+ end
28
+
29
+ after do
30
+ Mongoid::Config.sessions.clear
31
+ end
32
+
33
+ end
34
+
35
+ describe "when passed an list sessions as an array" do
36
+
37
+ before do
38
+ Mongoid.use(:default => MASTER_URI, :slave => SLAVE_URI)
39
+ end
40
+
41
+ it "should have some sessions configured" do
42
+ Mongoid::Config.sessions.wont_be_nil
43
+ Mongoid::Config.sessions.wont_be_empty
44
+ end
45
+
46
+ it "should have sessions named slaves and default configured" do
47
+ Mongoid::Config.sessions.has_key?(:default).must_equal true
48
+ Mongoid::Config.sessions.has_key?(:default).must_equal true
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,3 @@
1
+ require 'mongoid'
2
+ require 'mongoid-simplify'
3
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid-simplify
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sascha Wessel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: yard
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.2.1
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.8.2.1
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 3.3.0
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 3.3.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: redcarpet
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: mongoid
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 3.0.5
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 3.0.5
78
+ description: makes it simple again to connect to mongodb with mongoid
79
+ email:
80
+ - swessel@gr4yweb.de
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE
88
+ - README.md
89
+ - Rakefile
90
+ - lib/mongoid-simplify.rb
91
+ - lib/mongoid-simplify/connection.rb
92
+ - lib/mongoid-simplify/version.rb
93
+ - mongoid-simplify.gemspec
94
+ - spec/mongoid_spec.rb
95
+ - spec/spec_helper.rb
96
+ homepage: http://github.com/gr4y/mongoid-simplify
97
+ licenses: []
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ none: false
110
+ requirements:
111
+ - - ! '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 1.8.24
117
+ signing_key:
118
+ specification_version: 3
119
+ summary: makes it simple again to connect to mongodb with mongoid
120
+ test_files:
121
+ - spec/mongoid_spec.rb
122
+ - spec/spec_helper.rb
123
+ has_rdoc: