Skip to content

Commit

Permalink
Initial commit, basic mongoid3?, 4? and 5? questions.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Sep 17, 2015
0 parents commit aa55f44
Show file tree
Hide file tree
Showing 22 changed files with 377 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Gemfile.lock
pkg
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--format documentation
--color
5 changes: 5 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
AllCops:
Exclude:
- vendor/**/*

inherit_from: .rubocop_todo.yml
24 changes: 24 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2015-09-17 09:24:51 -0400 using RuboCop version 0.33.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 3
# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 95

# Offense count: 2
Style/Documentation:
Exclude:
- 'lib/mongoid-compatibility/self.rb'
- 'lib/mongoid-compatibility/version.rb'

# Offense count: 1
# Configuration parameters: Exclude.
Style/FileName:
Exclude:
- 'lib/mongoid-compatibility.rb'
16 changes: 16 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
rvm:
- 2.2
- 2.1.1
- 2.0.0
- 1.9.3
- rbx-2.2.10
- jruby-19mode

services:
- mongodb

env:
- MONGOID_VERSION=3
- MONGOID_VERSION=4
- MONGOID_VERSION=5

3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### 0.1.0 (Next)

* Initial public release - [@dblock](https://github.com/dblock).
118 changes: 118 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
Contributing to Mongoid::Compatibility
=======================================

Mongoid::Compatibility is work of [many of contributors](https://github.com/dblock/mongoid-compatibility/graphs/contributors). You're encouraged to submit [pull requests](https://github.com/dblock/mongoid-compatibility/pulls), [propose features, ask questions and discuss issues](https://github.com/dblock/mongoid-compatibility/issues).

#### Fork the Project

Fork the [project on Github](https://github.com/dblock/mongoid-compatibility) and check out your copy.

```
git clone https://github.com/contributor/mongoid-compatibility.git
cd mongoid-compatibility
git remote add upstream https://github.com/dblock/mongoid-compatibility.git
```

#### Create a Topic Branch

Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.

```
git checkout master
git pull upstream master
git checkout -b my-feature-branch
```

#### Bundle Install and Test

Ensure that you can build the project and run tests.

```
bundle install
bundle exec rake
```

#### Write Tests

Try to write a test that reproduces the problem you're trying to fix or describes a feature that you want to build. Add to [spec/mongoid-compatibility](spec/mongoid-compatibility).

We definitely appreciate pull requests that highlight or reproduce a problem, even without a fix.

#### Write Code

Implement your feature or bug fix.

Ruby style is enforced with [Rubocop](https://github.com/bbatsov/rubocop), run `bundle exec rubocop` and fix any style issues highlighted.

Make sure that `bundle exec rake` completes without errors.

#### Write Documentation

Document any external behavior in the [README](README.md).

#### Update Changelog

Add a line to [CHANGELOG](CHANGELOG.md) under *Next Release*. Make it look like every other line, including your name and link to your Github account.

#### Commit Changes

Make sure git knows your name and email address:

```
git config --global user.name "Your Name"
git config --global user.email "contributor@example.com"
```

Writing good commit logs is important. A commit log should describe what changed and why.

```
git add ...
git commit
```

#### Push

```
git push origin my-feature-branch
```

#### Make a Pull Request

Go to https://github.com/contributor/mongoid-compatibility and select your feature branch. Click the 'Pull Request' button and fill out the form. Pull requests are usually reviewed within a few days.

#### Rebase

If you've been working on a change for a while, rebase with upstream/master.

```
git fetch upstream
git rebase upstream/master
git push origin my-feature-branch -f
```

#### Update CHANGELOG Again

Update the [CHANGELOG](CHANGELOG.md) with the pull request number. A typical entry looks as follows.

```
* [#123](https://github.com/dblock/mongoid-compatibility/pull/123): Reticulated splines - [@contributor](https://github.com/contributor).
```

Amend your previous commit and force push the changes.

```
git commit --amend
git push origin my-feature-branch -f
```

#### Check on Your Pull Request

Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above.

#### Be Patient

It's likely that your change will not be merged and that the nitpicky maintainers will ask you to do more, or fix seemingly benign problems. Hang on there!

#### Thank You

Please do know that we really appreciate and value your time and work. We love you, really.
23 changes: 23 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
source 'http://rubygems.org'

gemspec

case version = ENV['MONGOID_VERSION'] || '~> 5.0'
when /5/
gem 'mongoid', '~> 5.0'
when /4/
gem 'mongoid', '~> 4.0'
when /3/
gem 'mongoid', '~> 3.1'
else
gem 'mongoid', version
end

group :test do
gem 'rspec'
end

group :development do
gem 'rake'
gem 'rubocop', '0.33.0'
end
22 changes: 22 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) 2015 Daniel Doubrovkine, Artsy and Contributors

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
Mongoid::Compatibility
=======================

[![Gem Version](http://img.shields.io/gem/v/mongoid-compatibility.svg)](http://badge.fury.io/rb/mongoid-compatibility)
[![Build Status](http://img.shields.io/travis/dblock/mongoid-compatibility.svg)](https://travis-ci.org/dblock/mongoid-compatibility)
[![Dependency Status](https://gemnasium.com/dblock/mongoid-compatibility.svg)](https://gemnasium.com/dblock/mongoid-compatibility)
[![Code Climate](https://codeclimate.com/github/dblock/mongoid-compatibility.svg)](https://codeclimate.com/github/dblock/mongoid-compatibility)

Compatibility helpers for Mongoid 3, 4 and 5.

### Install

Add `mongoid-compatibility` to your Gemfile.

```
gem 'mongoid-compatibility'
```

### Use

```
Mongoid::Compatibility.mongoid3? # => is this Mongoid 3.x?
Mongoid::Compatibility.mongoid4? # => is this Mongoid 4.x?
Mongoid::Compatibility.mongoid5? # => is this Mongoid 5.x?
```

### Contribute

See [CONTRIBUTING](CONTRIBUTING.md).

### Copyright and License

Copyright Daniel Doubrovkine and Contributors, Artsy Inc., 2015

[MIT License](LICENSE.md)
16 changes: 16 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require 'rubygems'
require 'bundler/gem_tasks'

Bundler.setup :default, :development

require 'rspec/core'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end

require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop)

task default: [:rubocop, :spec]
5 changes: 5 additions & 0 deletions lib/mongoid-compatibility.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'mongoid'
require 'active_support'

require 'mongoid-compatibility/self'
require 'mongoid-compatibility/version'
5 changes: 5 additions & 0 deletions lib/mongoid-compatibility/self.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Mongoid
module Compatibility
VERSION = '0.1.0'
end
end
17 changes: 17 additions & 0 deletions lib/mongoid-compatibility/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Mongoid
module Compatibility
module Version
def self.mongoid3?
Mongoid::VERSION =~ /^3\./
end

def self.mongoid4?
Mongoid::VERSION =~ /^4\./
end

def self.mongoid5?
Mongoid::VERSION =~ /^5\./
end
end
end
end
1 change: 1 addition & 0 deletions lib/mongoid_compatibility.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'mongoid-compatibility'
18 changes: 18 additions & 0 deletions mongoid-compatibility.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
require 'mongoid-compatibility/self'

Gem::Specification.new do |s|
s.name = 'mongoid-compatibility'
s.version = Mongoid::Compatibility::VERSION
s.authors = ['Daniel Doubrovkine']
s.email = 'dblock@dblock.org'
s.platform = Gem::Platform::RUBY
s.required_rubygems_version = '>= 1.3.6'
s.files = `git ls-files`.split("\n")
s.require_paths = ['lib']
s.homepage = 'http://github.com/dblock/mongoid-compatibility'
s.licenses = ['MIT']
s.summary = 'Compatibility helpers for Mongoid.'
s.add_dependency 'mongoid', '>= 3.0.0'
s.add_dependency 'activesupport'
end
9 changes: 9 additions & 0 deletions spec/config/mongoid3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
test:
sessions:
default:
database: mongoid-compatibility
hosts:
- localhost:27017
options:
raise_not_found_error: false
safe: true
8 changes: 8 additions & 0 deletions spec/config/mongoid4.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test:
sessions:
default:
database: mongoid-compatibility
hosts:
- localhost:27017
options:
raise_not_found_error: false
8 changes: 8 additions & 0 deletions spec/config/mongoid5.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
test:
clients:
default:
database: mongoid-compatibility
hosts:
- localhost:27017
options:
raise_not_found_error: false
7 changes: 7 additions & 0 deletions spec/mongoid-compatibility/self_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'

describe Mongoid::Compatibility do
it 'has a version' do
expect(Mongoid::Compatibility::VERSION).not_to be_nil
end
end
9 changes: 9 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))

require 'rubygems'
require 'rspec'
require 'mongoid-compatibility'

require 'support/mongoid'

RSpec.configure(&:raise_errors_for_deprecations!)
24 changes: 24 additions & 0 deletions spec/support/mongoid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ENV['MONGOID_ENV'] = 'test'

if Mongoid::Compatibility::Version.mongoid3?
Mongoid.load! 'spec/config/mongoid3.yml'
elsif Mongoid::Compatibility::Version.mongoid4?
Mongoid.load! 'spec/config/mongoid4.yml'
elsif Mongoid::Compatibility::Version.mongoid5?
Mongoid.load! 'spec/config/mongoid5.yml'
else
fail "unsupported Mongoid version #{Mongoid::VERSION}"
end

RSpec.configure do |config|
config.before do
Mongoid.purge!
end
config.after(:all) do
if Mongoid::Compatibility::Version.mongoid3? || Mongoid::Compatibility::Version.mongoid4?
Mongoid.default_session.drop
else
Mongoid::Clients.default.database.drop
end
end
end

0 comments on commit aa55f44

Please sign in to comment.