popular 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MDZmMzVhOWMxNzU4YTQ0YjlmMTQwODcyNzcyZDBmMTY3MTk5N2I0NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YmRlZWFlMjNjZTRlZWQ5NjgxZGY1NWIzZDIxZjcxZjIyY2NjMWQ2Yg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YTUzYjRjNzI2ZTk0YzFiZjA0NjU5YzQ0MzUzOWM2M2ZlMjM1M2JjMWYwYjcw
|
10
|
+
OTQ0YjM1MzljZTBmNWFkNDczNDAxMDVmMzk5ZGQxMTMzNDRhOTk3OGM3ZmFm
|
11
|
+
ZWZjYjlhYjE2NDJiZDhhZDI1OTAxOTVkMjIyZDNiNWRmMTgyYWE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTdmODI0Njk3M2ZjYTFkNWYwM2FjODBlOTMyMTA2ZTk2MjE4NzhlZDRjNTFj
|
14
|
+
YjUxNjM2NmQ5MGRmZDk0ODM2MTJjZDg4YTEyZTNlYjcxNmVjYjZhMzkzODI3
|
15
|
+
MmZmOGFiZGE3MDllNGI4YzQwN2UyNzVlZTg3ZGVjYzI3YTY3MGQ=
|
data/README.md
CHANGED
@@ -3,12 +3,11 @@
|
|
3
3
|
[![Build Status](https://travis-ci.org/thejchap/popular.svg?branch=master)](https://travis-ci.org/thejchap/popular)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/thejchap/popular.png)](https://codeclimate.com/github/thejchap/popular)
|
5
5
|
[![Code Coverage](https://codeclimate.com/github/thejchap/popular/coverage.png)](https://codeclimate.com/github/thejchap/popular)
|
6
|
+
[![Inline docs](http://inch-pages.github.io/github/thejchap/popular.png)](http://inch-pages.github.io/github/thejchap/popular)
|
6
7
|
[![Dependency Status](https://gemnasium.com/thejchap/popular.svg)](https://gemnasium.com/thejchap/popular)
|
7
8
|
|
8
9
|
Popular is a friendship gem designed for Rails/ActiveRecord models.
|
9
10
|
|
10
|
-
### THIS IS A VERY YOUNG GEM. YOU HAVE BEEN WARNED
|
11
|
-
|
12
11
|
## Installation
|
13
12
|
|
14
13
|
Add this line to your application's Gemfile:
|
@@ -23,13 +22,61 @@ Or install it yourself as:
|
|
23
22
|
|
24
23
|
$ gem install popular
|
25
24
|
|
25
|
+
### Database Migration
|
26
|
+
|
27
|
+
Popular uses a friendships table to store friendship relationships.
|
28
|
+
To get up and running, use the following command:
|
29
|
+
|
30
|
+
rails g popular:migration
|
31
|
+
rake db:migrate
|
32
|
+
|
26
33
|
## Usage
|
27
34
|
|
28
|
-
|
35
|
+
### Model
|
36
|
+
|
37
|
+
To get started using Popular, simply add `popular` to your model, (ie: `app/models/user.rb`)
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
class User < ActiveRecord::Base
|
41
|
+
popular
|
42
|
+
end
|
43
|
+
|
44
|
+
@sam = User.create name: "Samuel"
|
45
|
+
@jackson = User.create name: "Jackson"
|
46
|
+
|
47
|
+
@sam.friends_with? @jackson #=> false
|
48
|
+
@sam.befriend @jackson
|
49
|
+
@sam.friends_with? @jackson #=> true
|
50
|
+
@sam.unfriend @jackson
|
51
|
+
@sam.friends_with? @jackson #=> false
|
52
|
+
```
|
53
|
+
|
54
|
+
### Callbacks
|
55
|
+
|
56
|
+
Popular provides callbacks that are fired around friendship creation. Available callbacks are:
|
57
|
+
- after_befriend
|
58
|
+
- before_befriend
|
59
|
+
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
class User < ActiveRecord::Base
|
63
|
+
popular
|
64
|
+
after_befriend :notify
|
65
|
+
|
66
|
+
def notify
|
67
|
+
puts "Friendship created successfully"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
@justin = User.create name: "Justin"
|
72
|
+
@jenny = User.create name: "Jenny"
|
73
|
+
|
74
|
+
@justin.befriend @jenny #=> "Friendship created successfully"
|
75
|
+
```
|
29
76
|
|
30
77
|
## Contributing
|
31
78
|
|
32
|
-
1. Fork it ( http://github.com
|
79
|
+
1. Fork it ( http://github.com/thejchap/popular/fork )
|
33
80
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
81
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
82
|
4. Push to the branch (`git push origin my-new-feature`)
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
module Popular
|
4
|
+
class MigrationGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
|
7
|
+
desc "Generates migration for popular (friendships table)"
|
8
|
+
|
9
|
+
def self.orm
|
10
|
+
Rails::Generators.options[:rails][:orm]
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.source_root
|
14
|
+
File.join(File.dirname(__FILE__), 'templates', (orm.to_s unless orm.class.eql?(String)) )
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.orm_has_migration?
|
18
|
+
[:active_record].include? orm
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.next_migration_number(path)
|
22
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
23
|
+
end
|
24
|
+
|
25
|
+
def create_migration_file
|
26
|
+
if self.class.orm_has_migration?
|
27
|
+
migration_template 'migration.rb', 'db/migrate/popular_migration'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class PopularMigration < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
create_table :friendships do |t|
|
4
|
+
|
5
|
+
t.references :popular_model, polymorphic: true
|
6
|
+
t.references :friend, polymorphic: true
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
|
11
|
+
add_index :friendships, [:popular_model_id, :popular_model_type]
|
12
|
+
add_index :friendships, [:friend_id, :friend_type]
|
13
|
+
end
|
14
|
+
|
15
|
+
def down
|
16
|
+
drop_table :friendships
|
17
|
+
end
|
18
|
+
end
|
data/lib/popular/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: popular
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- thejchap
|
@@ -152,6 +152,8 @@ files:
|
|
152
152
|
- LICENSE.txt
|
153
153
|
- README.md
|
154
154
|
- Rakefile
|
155
|
+
- lib/generators/popular/migration/migration_generator.rb
|
156
|
+
- lib/generators/popular/migration/templates/active_record/migration.rb
|
155
157
|
- lib/popular.rb
|
156
158
|
- lib/popular/extenders/popular.rb
|
157
159
|
- lib/popular/friendship.rb
|