Skip to content

Commit

Permalink
Release v0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
pmviva committed Nov 19, 2015
0 parents commit ddc8a58
Show file tree
Hide file tree
Showing 64 changed files with 1,236 additions and 0 deletions.
Empty file added .empty
Empty file.
15 changes: 15 additions & 0 deletions .gitignore
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 added .keep
Empty file.
2 changes: 2 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--color
--require spec_helper
1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
follow_system
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-2.2.1
24 changes: 24 additions & 0 deletions .travis.yml
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
7 changes: 7 additions & 0 deletions Appraisals
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
4 changes: 4 additions & 0 deletions Gemfile
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
22 changes: 22 additions & 0 deletions LICENSE.txt
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.
93 changes: 93 additions & 0 deletions README.md
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

8 changes: 8 additions & 0 deletions Rakefile
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

31 changes: 31 additions & 0 deletions follow_system.gemspec
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 added gemfiles/.empty
Empty file.
Empty file added gemfiles/.gitignore
Empty file.
Empty file added gemfiles/.keep
Empty file.
7 changes: 7 additions & 0 deletions gemfiles/rails4.1.gemfile
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 => "../"
7 changes: 7 additions & 0 deletions gemfiles/rails4.2.gemfile
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 added lib/.empty
Empty file.
Empty file added lib/.gitignore
Empty file.
Empty file added lib/.keep
Empty file.
45 changes: 45 additions & 0 deletions lib/follow_system.rb
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 added lib/follow_system/.empty
Empty file.
Empty file added lib/follow_system/.gitignore
Empty file.
Empty file added lib/follow_system/.keep
Empty file.
Loading

0 comments on commit ddc8a58

Please sign in to comment.