mongoid_toggle 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/.travis.yml +2 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +41 -0
- data/LICENSE.md +20 -0
- data/README.md +36 -0
- data/Rakefile +32 -0
- data/init.rb +3 -0
- data/lib/mongoid/toggle.rb +36 -0
- data/lib/mongoid/toggle/version.rb +14 -0
- data/lib/mongoid_toggle.rb +3 -0
- data/mongoid_toggle.gemspec +59 -0
- metadata +107 -0
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use ruby-1.9.3-head@mongoid_toggle --create
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activemodel (3.2.2)
|
5
|
+
activesupport (= 3.2.2)
|
6
|
+
builder (~> 3.0.0)
|
7
|
+
activesupport (3.2.2)
|
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.5)
|
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.1.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,36 @@
|
|
1
|
+
# MongoidToggle [![Build Status](https://secure.travis-ci.org/Langwhich/mongoid_toggle.png)](https://secure.travis-ci.org/Langwhich/mongoid_toggle.png)
|
2
|
+
|
3
|
+
MongoidToggle adds a simple function to mongoid documents to toggle boolean
|
4
|
+
values with optional save for the record.
|
5
|
+
|
6
|
+
## Install
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'mongoid_toggle'
|
10
|
+
```
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
```ruby
|
15
|
+
class Person
|
16
|
+
include Mongoid::Document
|
17
|
+
include Mongoid::Toggle
|
18
|
+
|
19
|
+
field :name, :type => String
|
20
|
+
field :is_active, :type => Boolean
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
p = Person.first
|
26
|
+
|
27
|
+
# This call toggles is_active and saves the record
|
28
|
+
p.toggle! :is_active
|
29
|
+
|
30
|
+
# This call toggles is_active without saving the record
|
31
|
+
p.toggle :is_active
|
32
|
+
```
|
33
|
+
|
34
|
+
## Credits
|
35
|
+
|
36
|
+
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/toggle/version'
|
18
|
+
|
19
|
+
Jeweler::Tasks.new do |gem|
|
20
|
+
gem.name = 'mongoid_toggle'
|
21
|
+
gem.version = Mongoid::Toggle::Version::STRING
|
22
|
+
gem.homepage = 'https://github.com/Langwhich/mongoid_toggle'
|
23
|
+
gem.license = 'MIT'
|
24
|
+
gem.summary = %Q{Toggle function for boolean 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,36 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
module Mongoid
|
3
|
+
module Toggle
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
autoload :Version, 'mongoid/toggle/version'
|
6
|
+
|
7
|
+
included do
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
end
|
12
|
+
|
13
|
+
module InstanceMethods
|
14
|
+
def toggle!(field_name)
|
15
|
+
process_toggle(field_name)
|
16
|
+
save
|
17
|
+
end
|
18
|
+
|
19
|
+
def toggle(field_name)
|
20
|
+
process_toggle(field_name)
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
def process_toggle(field_name)
|
26
|
+
field_definition = self.class.fields[field_name.to_s]
|
27
|
+
|
28
|
+
return false if field_definition.nil?
|
29
|
+
return false unless field_definition.type.to_s == 'Boolean'
|
30
|
+
|
31
|
+
write_attribute(field_name, !read_attribute(field_name))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -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_toggle"
|
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-03-26"
|
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/toggle.rb",
|
28
|
+
"lib/mongoid/toggle/version.rb",
|
29
|
+
"lib/mongoid_toggle.rb",
|
30
|
+
"mongoid_toggle.gemspec"
|
31
|
+
]
|
32
|
+
s.homepage = "https://github.com/Langwhich/mongoid_toggle"
|
33
|
+
s.licenses = ["MIT"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = "1.8.10"
|
36
|
+
s.summary = "Toggle function for boolean 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_toggle
|
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-03-26 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mongoid
|
17
|
+
requirement: &70346477903220 !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: *70346477903220
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: redcarpet
|
28
|
+
requirement: &70346477902620 !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: *70346477902620
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: yard
|
39
|
+
requirement: &70346477901780 !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: *70346477901780
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: jeweler
|
50
|
+
requirement: &70346477900860 !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: *70346477900860
|
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/toggle.rb
|
76
|
+
- lib/mongoid/toggle/version.rb
|
77
|
+
- lib/mongoid_toggle.rb
|
78
|
+
- mongoid_toggle.gemspec
|
79
|
+
homepage: https://github.com/Langwhich/mongoid_toggle
|
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: -2873932606155986534
|
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: Toggle function for boolean columns within mongoid
|
107
|
+
test_files: []
|