mongoid_activity 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/Gemfile +6 -0
- data/LICENSE +20 -0
- data/README.md +45 -0
- data/Rakefile +46 -0
- data/VERSION +1 -0
- data/lib/mongoid_activity.rb +30 -0
- data/mongoid_activity.gemspec +61 -0
- data/spec/models/task.rb +4 -0
- data/spec/mongoid_activity_spec.rb +47 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +28 -0
- metadata +109 -0
data/.document
ADDED
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Mauricio Zaffari
|
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,45 @@
|
|
1
|
+
Mongoid Activity
|
2
|
+
============
|
3
|
+
|
4
|
+
Mongoid Activity is a simple gem to include active state to your Mongoid models.
|
5
|
+
|
6
|
+
Installation
|
7
|
+
--------
|
8
|
+
|
9
|
+
In your Gemfile:
|
10
|
+
|
11
|
+
source 'http://rubygems.org'
|
12
|
+
|
13
|
+
gem 'mongoid_activity'
|
14
|
+
|
15
|
+
Then:
|
16
|
+
|
17
|
+
bundle install
|
18
|
+
|
19
|
+
Examples
|
20
|
+
--------
|
21
|
+
|
22
|
+
class Task
|
23
|
+
include Mongoid::Document
|
24
|
+
include Mongoid::Activity
|
25
|
+
|
26
|
+
field :description
|
27
|
+
end
|
28
|
+
|
29
|
+
After that you gain activity methods:
|
30
|
+
|
31
|
+
t = Task.create :description => "Finish mongoid_activity gem"
|
32
|
+
t.activate!
|
33
|
+
=> true
|
34
|
+
t.active?
|
35
|
+
=> true
|
36
|
+
t.deactivate!
|
37
|
+
=> true
|
38
|
+
t.inactive?
|
39
|
+
=> true
|
40
|
+
t.active?
|
41
|
+
=> false
|
42
|
+
Product.active.size
|
43
|
+
=> 0
|
44
|
+
Product.inactive.size
|
45
|
+
=> 1
|
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "mongoid_activity"
|
8
|
+
gem.summary = %Q{Simple gem to include active state to your Mongoid models}
|
9
|
+
gem.description = %Q{Simpler than a full state machine :)}
|
10
|
+
gem.email = "mauricio@papodenerd.net"
|
11
|
+
gem.homepage = "http://github.com/mauriciozaffari/mongoid_activity"
|
12
|
+
gem.authors = ["Mauricio Zaffari"]
|
13
|
+
gem.add_dependency "mongoid", ">= 2.0.0.beta"
|
14
|
+
gem.add_development_dependency "rspec", ">= 1.2.9"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'spec/rake/spectask'
|
23
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
26
|
+
end
|
27
|
+
|
28
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
29
|
+
spec.libs << 'lib' << 'spec'
|
30
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
31
|
+
spec.rcov = true
|
32
|
+
end
|
33
|
+
|
34
|
+
task :spec => :check_dependencies
|
35
|
+
|
36
|
+
task :default => :spec
|
37
|
+
|
38
|
+
require 'rake/rdoctask'
|
39
|
+
Rake::RDocTask.new do |rdoc|
|
40
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
41
|
+
|
42
|
+
rdoc.rdoc_dir = 'rdoc'
|
43
|
+
rdoc.title = "mongoid_activity #{version}"
|
44
|
+
rdoc.rdoc_files.include('README*')
|
45
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
46
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.2
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Mongoid::Activity
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
field :active, :type => Boolean
|
6
|
+
index :active
|
7
|
+
|
8
|
+
scope :inactive, :where => { :active => false }
|
9
|
+
scope :active, :where => { :active => true }
|
10
|
+
|
11
|
+
def activate!
|
12
|
+
new_record? ? self.active = true : update_attributes(:active => true)
|
13
|
+
active?
|
14
|
+
end
|
15
|
+
|
16
|
+
def deactivate!
|
17
|
+
new_record? ? self.active = false : update_attributes(:active => false)
|
18
|
+
inactive?
|
19
|
+
end
|
20
|
+
|
21
|
+
def active?
|
22
|
+
active
|
23
|
+
end
|
24
|
+
|
25
|
+
def inactive?
|
26
|
+
!active
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mongoid_activity}
|
8
|
+
s.version = "0.0.2"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Mauricio Zaffari"]
|
12
|
+
s.date = %q{2010-09-22}
|
13
|
+
s.description = %q{Simpler than a full state machine :)}
|
14
|
+
s.email = %q{mauricio@papodenerd.net}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"Gemfile",
|
23
|
+
"LICENSE",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"lib/mongoid_activity.rb",
|
28
|
+
"mongoid_activity.gemspec",
|
29
|
+
"spec/models/task.rb",
|
30
|
+
"spec/mongoid_activity_spec.rb",
|
31
|
+
"spec/spec.opts",
|
32
|
+
"spec/spec_helper.rb"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/mauriciozaffari/mongoid_activity}
|
35
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.7}
|
38
|
+
s.summary = %q{Simple gem to include active state to your Mongoid models}
|
39
|
+
s.test_files = [
|
40
|
+
"spec/models/task.rb",
|
41
|
+
"spec/mongoid_activity_spec.rb",
|
42
|
+
"spec/spec_helper.rb"
|
43
|
+
]
|
44
|
+
|
45
|
+
if s.respond_to? :specification_version then
|
46
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
47
|
+
s.specification_version = 3
|
48
|
+
|
49
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
50
|
+
s.add_runtime_dependency(%q<mongoid>, [">= 2.0.0.beta"])
|
51
|
+
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<mongoid>, [">= 2.0.0.beta"])
|
54
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
55
|
+
end
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<mongoid>, [">= 2.0.0.beta"])
|
58
|
+
s.add_dependency(%q<rspec>, [">= 1.2.9"])
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
data/spec/models/task.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe Mongoid::Activity do
|
4
|
+
before(:each) do
|
5
|
+
@task = Task.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "not saved" do
|
9
|
+
it "should be activable" do
|
10
|
+
@task.activate!
|
11
|
+
@task.active?.should be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should be deactivable" do
|
15
|
+
@task.activate!
|
16
|
+
@task.deactivate!
|
17
|
+
@task.inactive?.should be_true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "saved" do
|
22
|
+
before(:each) do
|
23
|
+
@task.save
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should be activable" do
|
27
|
+
@task.activate!
|
28
|
+
@task.active?.should be_true
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should be deactivable" do
|
32
|
+
@task.activate!
|
33
|
+
@task.deactivate!
|
34
|
+
@task.inactive?.should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should have a active scope" do
|
38
|
+
@task.activate!
|
39
|
+
Task.active.first.should == @task
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should have a inactive scope" do
|
43
|
+
@task.deactivate!
|
44
|
+
Task.inactive.first.should == @task
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'mongoid'
|
4
|
+
require 'database_cleaner'
|
5
|
+
require 'mongoid_activity'
|
6
|
+
|
7
|
+
Mongoid.configure do |config|
|
8
|
+
name = "mongoid_activity_test"
|
9
|
+
config.master = Mongo::Connection.new.db(name)
|
10
|
+
end
|
11
|
+
|
12
|
+
Dir["#{File.dirname(__FILE__)}/models/*.rb"].each { |file| require file }
|
13
|
+
|
14
|
+
DatabaseCleaner.orm = "mongoid"
|
15
|
+
|
16
|
+
Spec::Runner.configure do |config|
|
17
|
+
config.before(:all) do
|
18
|
+
DatabaseCleaner.strategy = :truncation
|
19
|
+
end
|
20
|
+
|
21
|
+
config.before(:each) do
|
22
|
+
DatabaseCleaner.start
|
23
|
+
end
|
24
|
+
|
25
|
+
config.after(:each) do
|
26
|
+
DatabaseCleaner.clean
|
27
|
+
end
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid_activity
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Mauricio Zaffari
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-09-22 00:00:00 -03:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: mongoid
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 2
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
- beta
|
33
|
+
version: 2.0.0.beta
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
segments:
|
45
|
+
- 1
|
46
|
+
- 2
|
47
|
+
- 9
|
48
|
+
version: 1.2.9
|
49
|
+
type: :development
|
50
|
+
version_requirements: *id002
|
51
|
+
description: Simpler than a full state machine :)
|
52
|
+
email: mauricio@papodenerd.net
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files:
|
58
|
+
- LICENSE
|
59
|
+
- README.md
|
60
|
+
files:
|
61
|
+
- .document
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- VERSION
|
68
|
+
- lib/mongoid_activity.rb
|
69
|
+
- mongoid_activity.gemspec
|
70
|
+
- spec/models/task.rb
|
71
|
+
- spec/mongoid_activity_spec.rb
|
72
|
+
- spec/spec.opts
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
has_rdoc: true
|
75
|
+
homepage: http://github.com/mauriciozaffari/mongoid_activity
|
76
|
+
licenses: []
|
77
|
+
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options:
|
80
|
+
- --charset=UTF-8
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
segments:
|
97
|
+
- 0
|
98
|
+
version: "0"
|
99
|
+
requirements: []
|
100
|
+
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.3.7
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Simple gem to include active state to your Mongoid models
|
106
|
+
test_files:
|
107
|
+
- spec/models/task.rb
|
108
|
+
- spec/mongoid_activity_spec.rb
|
109
|
+
- spec/spec_helper.rb
|