-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit ddc8a58
Showing
64 changed files
with
1,236 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,15 @@ | ||
/.bundle/ | ||
/.yardoc | ||
/Gemfile.lock | ||
/_yardoc/ | ||
/coverage/ | ||
/doc/ | ||
/gemfiles/*.lock | ||
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
*.bundle | ||
*.so | ||
*.o | ||
*.a | ||
mkmf.log |
Empty file.
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,2 @@ | ||
--color | ||
--require spec_helper |
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 @@ | ||
follow_system |
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 @@ | ||
ruby-2.2.1 |
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,24 @@ | ||
language: | ||
- ruby | ||
|
||
rvm: | ||
- 2.0.0 | ||
- 2.1.3 | ||
- 2.2.1 | ||
|
||
gemfile: | ||
- gemfiles/rails4.1.gemfile | ||
- gemfiles/rails4.2.gemfile | ||
|
||
install: | ||
- "gem install bundler" | ||
- "travis_retry bundle install" | ||
|
||
before_script: | ||
|
||
script: | ||
- "bundle exec rake" | ||
|
||
branches: | ||
only: | ||
- master |
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,7 @@ | ||
appraise "rails4.1" do | ||
gem "rails", "4.1.13" | ||
end | ||
|
||
appraise "rails4.2" do | ||
gem "rails", "4.2.4" | ||
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,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in follow_system.gemspec | ||
gemspec |
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,22 @@ | ||
Copyright (c) 2014 Pablo Martin Viva | ||
|
||
MIT License | ||
|
||
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. |
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,93 @@ | ||
# FollowSystem | ||
|
||
[![Build Status](https://travis-ci.org/pmviva/follow_system.png?branch=master)](https://travis-ci.org/pmviva/follow_system) | ||
[![Gem Version](https://badge.fury.io/rb/follow_system.svg)](http://badge.fury.io/rb/follow_system) | ||
|
||
An active record follow system developed using ruby on rails 4.1 applying domain driven design and test driven development principles. | ||
|
||
This gem is heavily influenced by cmer/socialization. | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
```ruby | ||
gem 'follow_system' | ||
``` | ||
|
||
And then execute: | ||
|
||
```ruby | ||
$ bundle | ||
``` | ||
|
||
Or install it yourself as: | ||
|
||
```ruby | ||
$ gem install follow_system | ||
``` | ||
|
||
## Usage | ||
|
||
### Run the generator | ||
|
||
```ruby | ||
$ rails g follow_system | ||
``` | ||
|
||
Let's suppose for a moment that you have a celebrity news application and a User can follow a Celebrity or several Celebrity models. | ||
The user model becomes the follower and the celebrity model becomes the followee. | ||
|
||
### Celebrity object | ||
```ruby | ||
class Celebrity < ActiveRecord::Base | ||
act_as_followee | ||
|
||
validates :name, { presence: true, uniqueness: true } | ||
end | ||
``` | ||
|
||
### User object | ||
```ruby | ||
class User < ActiveRecord::Base | ||
act_as_follower | ||
|
||
validates :username, { presence: true, uniqueness: true } | ||
end | ||
``` | ||
|
||
### Followee object methods | ||
```ruby | ||
celebrity.is_followee? # returns true | ||
|
||
celebrity.followed_by?(user) # returns true if user follows the celebrity object, false otherwise | ||
|
||
celebrity.followers_by(User) # returns a scope of FollowSystem::Follow join model that belongs to the celebrity object and belongs to follower objects of type User | ||
``` | ||
|
||
|
||
### Follower object methods | ||
```ruby | ||
user.is_follower? # returns true | ||
|
||
user.follow(celebrity) # Creates an instance of FollowSystem::Follow join model associating the user object and the celebrity object, returns true if succeded, false otherwise | ||
|
||
user.unfollow(celebrity) # Destroys an instance of FollowSystem::Follow join model that associates the user object and the celebrity object, returns true if succeded, false otherwise | ||
|
||
user.toggle_follow(celebrity) # Follows / unfollows the celebrity | ||
|
||
user.follows?(celebrity) # returns true if the user object follows the celebrity object, false otherwise | ||
|
||
user.followees_by(Celebrity) # returns a scope of FollowSystem::Follow join model that belongs to the user object and belongs to followee objects of type Celebrity | ||
``` | ||
|
||
For more information read the [api documentation](http://rubydoc.info/gems/follow_system). | ||
|
||
## Contributing | ||
|
||
1. Fork it ( https://github.com/pmviva/follow_system/fork ) | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Add some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create a new Pull Request | ||
|
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,8 @@ | ||
require "bundler/gem_tasks" | ||
|
||
task :default => [:spec] | ||
desc 'run Rspec specs' | ||
task :spec do | ||
sh 'rspec spec' | ||
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,31 @@ | ||
# coding: utf-8 | ||
lib = File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'follow_system/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "follow_system" | ||
spec.version = FollowSystem::VERSION | ||
spec.authors = ["Pablo Martin Viva"] | ||
spec.email = ["pmviva@gmail.com"] | ||
spec.summary = %q{An active record follow system.} | ||
spec.description = %q{An active record follow system developed using ruby on rails 4.1 applying domain driven design and test driven development principles.} | ||
spec.homepage = "http://github.com/pmviva/follow_system" | ||
spec.license = "MIT" | ||
|
||
spec.files = `git ls-files -z`.split("\x0") | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
spec.require_paths = ["lib"] | ||
spec.required_ruby_version = Gem::Requirement.new(">= 2.0.0") | ||
|
||
spec.add_dependency "rails", [ ">= 4.1", "< 5" ] | ||
|
||
spec.add_development_dependency "appraisal", "~> 2.1" | ||
spec.add_development_dependency "bundler", "~> 1.10" | ||
spec.add_development_dependency "rake", "~> 10.4" | ||
spec.add_development_dependency "rspec", "~> 3.3" | ||
spec.add_development_dependency "shoulda-matchers", "~> 2.8" | ||
spec.add_development_dependency "sqlite3", "~> 1.3" | ||
end | ||
|
Empty file.
Empty file.
Empty file.
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,7 @@ | ||
# This file was generated by Appraisal | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "rails", "4.1.13" | ||
|
||
gemspec :path => "../" |
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,7 @@ | ||
# This file was generated by Appraisal | ||
|
||
source "https://rubygems.org" | ||
|
||
gem "rails", "4.2.4" | ||
|
||
gemspec :path => "../" |
Empty file.
Empty file.
Empty file.
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,45 @@ | ||
require 'follow_system/follow' | ||
require 'follow_system/followee' | ||
require 'follow_system/follower' | ||
|
||
### | ||
# FollowSystem module | ||
# | ||
# This module defines common behavior in follow system | ||
### | ||
module FollowSystem | ||
### | ||
# Specifies if self can be followed by {Follower} objects | ||
# | ||
# @return [Boolean] | ||
### | ||
def is_followee? | ||
false | ||
end | ||
|
||
### | ||
# Specifies if self can follow {Followee} objects | ||
# | ||
# @return [Boolean] | ||
### | ||
def is_follower? | ||
false | ||
end | ||
|
||
### | ||
# Instructs self to act as followee | ||
### | ||
def act_as_followee | ||
include Followee | ||
end | ||
|
||
### | ||
# Instructs self to act as follower | ||
### | ||
def act_as_follower | ||
include Follower | ||
end | ||
end | ||
|
||
ActiveRecord::Base.extend FollowSystem | ||
|
Empty file.
Empty file.
Empty file.
Oops, something went wrong.