This repository has been archived by the owner on Jun 25, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Luke Cunningham
committed
Nov 17, 2010
1 parent
e034a86
commit 70790d1
Showing
11 changed files
with
413 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,13 @@ | ||
# rcov generated | ||
coverage | ||
|
||
# rdoc generated | ||
rdoc | ||
|
||
# yard generated | ||
doc | ||
.yardoc | ||
|
||
# bundler | ||
.bundle | ||
|
||
# jeweler generated | ||
pkg | ||
|
||
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore: | ||
# | ||
# * Create a file at ~/.gitignore | ||
# * Include files you want ignored | ||
# * Run: git config --global core.excludesfile ~/.gitignore | ||
# | ||
# After doing this, these files will be ignored in all your git projects, | ||
# saving you from having to 'pollute' every project you touch with them | ||
# | ||
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line) | ||
# | ||
# For MacOS: | ||
# | ||
#.DS_Store | ||
# | ||
# For TextMate | ||
#*.tmproj | ||
#tmtags | ||
# | ||
# For emacs: | ||
#*~ | ||
#\#* | ||
#.\#* | ||
# | ||
# For vim: | ||
#*.swp | ||
.DS_Store | ||
|
||
*.tmproj | ||
tmtags | ||
|
||
log/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
GEM | ||
remote: http://rubygems.org/ | ||
specs: | ||
activesupport (3.0.1) | ||
bson (1.1.2) | ||
bson_ext (1.1.2) | ||
columnize (0.3.2) | ||
diff-lcs (1.1.2) | ||
git (1.2.5) | ||
i18n (0.4.2) | ||
jeweler (1.5.1) | ||
bundler (~> 1.0.0) | ||
git (>= 1.2.5) | ||
rake | ||
jnunemaker-validatable (1.8.4) | ||
activesupport (>= 2.3.4) | ||
linecache (0.43) | ||
log_buddy (0.5.0) | ||
mongo (1.1.2) | ||
bson (>= 1.1.1) | ||
mongo_ext (0.19.3) | ||
mongo_mapper (0.8.6) | ||
activesupport (>= 2.3.4) | ||
jnunemaker-validatable (~> 1.8.4) | ||
plucky (~> 0.3.6) | ||
plucky (0.3.6) | ||
mongo (~> 1.1) | ||
rake (0.8.7) | ||
rcov (0.9.9) | ||
rspec (2.1.0) | ||
rspec-core (~> 2.1.0) | ||
rspec-expectations (~> 2.1.0) | ||
rspec-mocks (~> 2.1.0) | ||
rspec-core (2.1.0) | ||
rspec-expectations (2.1.0) | ||
diff-lcs (~> 1.1.2) | ||
rspec-mocks (2.1.0) | ||
ruby-debug (0.10.4) | ||
columnize (>= 0.1) | ||
ruby-debug-base (~> 0.10.4.0) | ||
ruby-debug-base (0.10.4) | ||
linecache (>= 0.3) | ||
yard (0.6.2) | ||
|
||
PLATFORMS | ||
ruby | ||
|
||
DEPENDENCIES | ||
bson_ext (= 1.1.2) | ||
bundler (~> 1.0.0) | ||
i18n | ||
jeweler (~> 1.5.1) | ||
log_buddy | ||
mongo (= 1.1.2) | ||
mongo_ext | ||
mongo_mapper | ||
rcov | ||
rspec (~> 2.1.0) | ||
ruby-debug | ||
yard (~> 0.6.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'mongo_mapper' | ||
|
||
require File.join(File.dirname(__FILE__), 'mongo_mapper', 'plugins', 'friendable') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
require File.join(File.dirname(__FILE__), 'friendable', 'friend_list') | ||
|
||
module MongoMapper | ||
module Plugins | ||
module Friendable | ||
|
||
def self.configure(model) | ||
model.class_eval do | ||
key :friend_list, FriendList | ||
|
||
key :followers_count, Integer, :default => 0 | ||
key :following_count, Integer, :default => 0 | ||
|
||
before_create :create_friend_list | ||
|
||
def friendable?; true; end | ||
end | ||
end | ||
|
||
module InstanceMethods | ||
|
||
def add_friend!(friend) | ||
return false if friend == self | ||
|
||
User.push_uniq(self.id, 'friend_list.following_ids' => friend.id) | ||
User.push_uniq(friend.id, 'friend_list.followers_ids' => self.id) | ||
User.increment(self.id, 'following_count' => 1) | ||
User.increment(friend.id, 'followers_count' => 1) | ||
|
||
on_add_friend(friend) | ||
end | ||
|
||
def on_add_friend(friend) | ||
raise NotImplementedError | ||
end | ||
|
||
def remove_friend!(friend) | ||
return false if friend == self | ||
|
||
User.pull(self.id, 'friend_list.following_ids' => friend.id) | ||
User.pull(friend.id, 'friend_list.followers_ids' => self.id) | ||
User.decrement(self.id, 'following_count' => 1) | ||
User.decrement(friend.id, 'followers_count' => 1) | ||
|
||
on_remove_friend(friend) | ||
end | ||
|
||
def on_remove_friend(friend) | ||
raise NotImplementedError | ||
end | ||
|
||
def followers | ||
User.find(self.friend_list.followers_ids) | ||
end | ||
|
||
def following | ||
User.find(self.friend_list.following_ids) | ||
end | ||
|
||
def following?(user) | ||
self.friend_list.following_ids.include?(user.id) | ||
end | ||
|
||
protected | ||
def create_friend_list | ||
self.friend_list = FriendList.new unless self.friend_list.present? | ||
end | ||
|
||
end | ||
|
||
module ClassMethods | ||
end | ||
|
||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class FriendList | ||
include MongoMapper::EmbeddedDocument | ||
|
||
key :followers_ids, Array, :typecast => 'ObjectId' | ||
key :following_ids, Array, :typecast => 'ObjectId' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# Generated by jeweler | ||
# DO NOT EDIT THIS FILE DIRECTLY | ||
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' | ||
# -*- encoding: utf-8 -*- | ||
|
||
Gem::Specification.new do |s| | ||
s.name = %q{mm-friendable} | ||
s.version = "0.0.0" | ||
|
||
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= | ||
s.authors = ["Luke Cunningham"] | ||
s.date = %q{2010-11-17} | ||
s.description = %q{A very simple mongomapper plugin to add friendship functionality to your application} | ||
s.email = %q{luke@icaruswings.com} | ||
s.extra_rdoc_files = [ | ||
"LICENSE.txt", | ||
"README.rdoc" | ||
] | ||
s.files = [ | ||
".document", | ||
".rspec", | ||
"Gemfile", | ||
"Gemfile.lock", | ||
"LICENSE.txt", | ||
"README.rdoc", | ||
"Rakefile", | ||
"VERSION", | ||
"lib/mm-friendable.rb", | ||
"lib/mongo_mapper/plugins/friendable.rb", | ||
"lib/mongo_mapper/plugins/friendable/friend_list.rb", | ||
"spec/mm-friendable_spec.rb", | ||
"spec/spec_helper.rb", | ||
"spec/support/models.rb" | ||
] | ||
s.homepage = %q{http://github.com/icaruswings/mm-friendable} | ||
s.licenses = ["MIT"] | ||
s.require_paths = ["lib"] | ||
s.rubygems_version = %q{1.3.7} | ||
s.summary = %q{A very simple mongomapper plugin to add friendship functionaity to your application} | ||
s.test_files = [ | ||
"spec/mm-friendable_spec.rb", | ||
"spec/spec_helper.rb", | ||
"spec/support/models.rb" | ||
] | ||
|
||
if s.respond_to? :specification_version then | ||
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION | ||
s.specification_version = 3 | ||
|
||
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then | ||
s.add_development_dependency(%q<mongo>, ["= 1.1.2"]) | ||
s.add_development_dependency(%q<bson_ext>, ["= 1.1.2"]) | ||
s.add_development_dependency(%q<mongo_ext>, [">= 0"]) | ||
s.add_development_dependency(%q<mongo_mapper>, [">= 0"]) | ||
s.add_development_dependency(%q<i18n>, [">= 0"]) | ||
s.add_development_dependency(%q<log_buddy>, [">= 0"]) | ||
s.add_development_dependency(%q<ruby-debug>, [">= 0"]) | ||
s.add_development_dependency(%q<rspec>, ["~> 2.1.0"]) | ||
s.add_development_dependency(%q<yard>, ["~> 0.6.0"]) | ||
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"]) | ||
s.add_development_dependency(%q<jeweler>, ["~> 1.5.1"]) | ||
s.add_development_dependency(%q<rcov>, [">= 0"]) | ||
else | ||
s.add_dependency(%q<mongo>, ["= 1.1.2"]) | ||
s.add_dependency(%q<bson_ext>, ["= 1.1.2"]) | ||
s.add_dependency(%q<mongo_ext>, [">= 0"]) | ||
s.add_dependency(%q<mongo_mapper>, [">= 0"]) | ||
s.add_dependency(%q<i18n>, [">= 0"]) | ||
s.add_dependency(%q<log_buddy>, [">= 0"]) | ||
s.add_dependency(%q<ruby-debug>, [">= 0"]) | ||
s.add_dependency(%q<rspec>, ["~> 2.1.0"]) | ||
s.add_dependency(%q<yard>, ["~> 0.6.0"]) | ||
s.add_dependency(%q<bundler>, ["~> 1.0.0"]) | ||
s.add_dependency(%q<jeweler>, ["~> 1.5.1"]) | ||
s.add_dependency(%q<rcov>, [">= 0"]) | ||
end | ||
else | ||
s.add_dependency(%q<mongo>, ["= 1.1.2"]) | ||
s.add_dependency(%q<bson_ext>, ["= 1.1.2"]) | ||
s.add_dependency(%q<mongo_ext>, [">= 0"]) | ||
s.add_dependency(%q<mongo_mapper>, [">= 0"]) | ||
s.add_dependency(%q<i18n>, [">= 0"]) | ||
s.add_dependency(%q<log_buddy>, [">= 0"]) | ||
s.add_dependency(%q<ruby-debug>, [">= 0"]) | ||
s.add_dependency(%q<rspec>, ["~> 2.1.0"]) | ||
s.add_dependency(%q<yard>, ["~> 0.6.0"]) | ||
s.add_dependency(%q<bundler>, ["~> 1.0.0"]) | ||
s.add_dependency(%q<jeweler>, ["~> 1.5.1"]) | ||
s.add_dependency(%q<rcov>, [">= 0"]) | ||
end | ||
end | ||
|
Oops, something went wrong.