mongoid_find_by 0.1.0

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/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use ruby-1.9.3-head@mongoid_find_by --create
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm:
2
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'mongoid', '~> 2.4.7'
4
+
5
+ group :development do
6
+ gem 'redcarpet', '~> 2.1.0'
7
+ gem 'yard', '~> 0.7.5'
8
+ gem 'jeweler', '~> 1.8.3'
9
+ end
10
+
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.2.3)
5
+ activesupport (= 3.2.3)
6
+ builder (~> 3.0.0)
7
+ activesupport (3.2.3)
8
+ i18n (~> 0.6)
9
+ multi_json (~> 1.0)
10
+ bson (1.6.1)
11
+ builder (3.0.0)
12
+ git (1.2.5)
13
+ i18n (0.6.0)
14
+ jeweler (1.8.3)
15
+ bundler (~> 1.0)
16
+ git (>= 1.2.5)
17
+ rake
18
+ rdoc
19
+ json (1.6.6)
20
+ mongo (1.6.1)
21
+ bson (~> 1.6.1)
22
+ mongoid (2.4.7)
23
+ activemodel (~> 3.1)
24
+ mongo (~> 1.3)
25
+ tzinfo (~> 0.3.22)
26
+ multi_json (1.2.0)
27
+ rake (0.9.2.2)
28
+ rdoc (3.12)
29
+ json (~> 1.4)
30
+ redcarpet (2.1.1)
31
+ tzinfo (0.3.32)
32
+ yard (0.7.5)
33
+
34
+ PLATFORMS
35
+ ruby
36
+
37
+ DEPENDENCIES
38
+ jeweler (~> 1.8.3)
39
+ mongoid (~> 2.4.7)
40
+ redcarpet (~> 2.1.0)
41
+ yard (~> 0.7.5)
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Langwhich GmbH <http://www.langwhich.com>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # MongoidFindBy [![Build Status](https://secure.travis-ci.org/Langwhich/mongoid_find_by.png)](https://secure.travis-ci.org/Langwhich/mongoid_find_by)
2
+
3
+ MongoidFindBy adds simple functions to mongoid documents to find documents
4
+ by dynamic fields.
5
+
6
+ ## Install
7
+
8
+ ```ruby
9
+ gem 'mongoid_find_by'
10
+ ```
11
+
12
+ ## Usage
13
+
14
+ ```ruby
15
+ class Person
16
+ include Mongoid::Document
17
+ include Mongoid::FindBy
18
+
19
+ field :name, :type => String
20
+ end
21
+ ```
22
+
23
+ ```ruby
24
+ # returns a single document
25
+ Person.find_by_name('Thomas')
26
+ Person.find_first_by_name('Thomas')
27
+ Person.find_last_by_name('Thomas')
28
+
29
+ # returns a document collection
30
+ Person.find_all_by_name('Thomas')
31
+
32
+ # throws Mongoid::Errors::DocumentNotFound
33
+ # exception for non existent documents
34
+ Person.find_by_name!('Thomas)
35
+ ```
36
+
37
+ ## Credits
38
+
39
+ Copyright (c) 2012 Langwhich GmbH <http://www.langwhich.com>
data/Rakefile ADDED
@@ -0,0 +1,32 @@
1
+ require 'rubygems'
2
+
3
+ begin
4
+ require 'bundler'
5
+ Bundler.setup(:default, :development)
6
+ rescue Bundler::BundlerError => e
7
+ $stderr.puts e.message
8
+ $stderr.puts 'Run `bundle install` to install missing gems'
9
+ exit e.status_code
10
+ end
11
+
12
+ require 'rake'
13
+ require 'jeweler'
14
+ require 'yard'
15
+
16
+ $:.push File.expand_path('../lib', __FILE__)
17
+ require 'mongoid/find_by/version'
18
+
19
+ Jeweler::Tasks.new do |gem|
20
+ gem.name = 'mongoid_find_by'
21
+ gem.version = Mongoid::FindBy::Version::STRING
22
+ gem.homepage = 'https://github.com/Langwhich/mongoid_find_by'
23
+ gem.license = 'MIT'
24
+ gem.summary = %Q{Finder function for dynamic columns within mongoid}
25
+ gem.email = 'thomas.boerger@langwhich.com'
26
+ gem.authors = ['Thomas Boerger', 'Tim Rudat']
27
+ end
28
+
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+ YARD::Rake::YardocTask.new
31
+
32
+ task :default => :version
data/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'mongoid_find_by'
@@ -0,0 +1,13 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Mongoid
3
+ module FindBy
4
+ module Version
5
+ MAJOR = 0
6
+ MINOR = 1
7
+ PATCH = 0
8
+ BUILD = nil
9
+
10
+ STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,45 @@
1
+ # -*- encoding : utf-8 -*-
2
+ module Mongoid
3
+ module FindBy
4
+ extend ActiveSupport::Concern
5
+ autoload :Version, 'mongoid/find_by/version'
6
+
7
+ included do
8
+ old_method_missing = if methods(false).member? :method_missing
9
+ method(:method_missing)
10
+ end
11
+
12
+ def method_missing(method_id, *args, &block)
13
+ conditions = {}
14
+ bang = false
15
+
16
+ case method_id.to_s
17
+ when /^find_(all|last||first)_?by_([_a-zA-Z]\w*)(!?)$/
18
+ finder_type = $1.blank? ? :first : $1.to_sym
19
+ bang = true if $3 == '!'
20
+
21
+ tokens = $2.split(/_and_/)
22
+ raise ArgumentError, 'Attributes and arguments does\'nt match' if tokens.size != args.size
23
+
24
+ tokens.each_with_index do |attr, i|
25
+ conditions[attr] = args[i]
26
+ end
27
+
28
+ result = find(finder_type, :conditions => conditions)
29
+
30
+ if result.nil? and bang
31
+ raise Mongoid::Errors::DocumentNotFound.new(self.class, args)
32
+ else
33
+ return result
34
+ end
35
+ else
36
+ if old_method_missing
37
+ old_method_missing.bind(self).call
38
+ else
39
+ super
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,2 @@
1
+ # -*- encoding : utf-8 -*-
2
+ require 'mongoid/find_by'
@@ -0,0 +1,59 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "mongoid_find_by"
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Thomas Boerger", "Tim Rudat"]
12
+ s.date = "2012-04-03"
13
+ s.email = "thomas.boerger@langwhich.com"
14
+ s.extra_rdoc_files = [
15
+ "LICENSE.md",
16
+ "README.md"
17
+ ]
18
+ s.files = [
19
+ ".rvmrc",
20
+ ".travis.yml",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.md",
24
+ "README.md",
25
+ "Rakefile",
26
+ "init.rb",
27
+ "lib/mongoid/find_by.rb",
28
+ "lib/mongoid/find_by/version.rb",
29
+ "lib/mongoid_find_by.rb",
30
+ "mongoid_find_by.gemspec"
31
+ ]
32
+ s.homepage = "https://github.com/Langwhich/mongoid_find_by"
33
+ s.licenses = ["MIT"]
34
+ s.require_paths = ["lib"]
35
+ s.rubygems_version = "1.8.10"
36
+ s.summary = "Finder function for dynamic columns within mongoid"
37
+
38
+ if s.respond_to? :specification_version then
39
+ s.specification_version = 3
40
+
41
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
42
+ s.add_runtime_dependency(%q<mongoid>, ["~> 2.4.7"])
43
+ s.add_development_dependency(%q<redcarpet>, ["~> 2.1.0"])
44
+ s.add_development_dependency(%q<yard>, ["~> 0.7.5"])
45
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
46
+ else
47
+ s.add_dependency(%q<mongoid>, ["~> 2.4.7"])
48
+ s.add_dependency(%q<redcarpet>, ["~> 2.1.0"])
49
+ s.add_dependency(%q<yard>, ["~> 0.7.5"])
50
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
51
+ end
52
+ else
53
+ s.add_dependency(%q<mongoid>, ["~> 2.4.7"])
54
+ s.add_dependency(%q<redcarpet>, ["~> 2.1.0"])
55
+ s.add_dependency(%q<yard>, ["~> 0.7.5"])
56
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
57
+ end
58
+ end
59
+
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid_find_by
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Thomas Boerger
9
+ - Tim Rudat
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-04-03 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: mongoid
17
+ requirement: &70163815477780 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ~>
21
+ - !ruby/object:Gem::Version
22
+ version: 2.4.7
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70163815477780
26
+ - !ruby/object:Gem::Dependency
27
+ name: redcarpet
28
+ requirement: &70163815493540 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 2.1.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: *70163815493540
37
+ - !ruby/object:Gem::Dependency
38
+ name: yard
39
+ requirement: &70163815492880 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ version: 0.7.5
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *70163815492880
48
+ - !ruby/object:Gem::Dependency
49
+ name: jeweler
50
+ requirement: &70163815492220 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: 1.8.3
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *70163815492220
59
+ description:
60
+ email: thomas.boerger@langwhich.com
61
+ executables: []
62
+ extensions: []
63
+ extra_rdoc_files:
64
+ - LICENSE.md
65
+ - README.md
66
+ files:
67
+ - .rvmrc
68
+ - .travis.yml
69
+ - Gemfile
70
+ - Gemfile.lock
71
+ - LICENSE.md
72
+ - README.md
73
+ - Rakefile
74
+ - init.rb
75
+ - lib/mongoid/find_by.rb
76
+ - lib/mongoid/find_by/version.rb
77
+ - lib/mongoid_find_by.rb
78
+ - mongoid_find_by.gemspec
79
+ homepage: https://github.com/Langwhich/mongoid_find_by
80
+ licenses:
81
+ - MIT
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ segments:
93
+ - 0
94
+ hash: -3443344411995683717
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ! '>='
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.10
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: Finder function for dynamic columns within mongoid
107
+ test_files: []