likeable 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,148 +1,16 @@
1
- Use Redis to Make your Ruby objects Likeable!
2
- ======
1
+ # Likeable Has Moved!!
3
2
 
4
- You like this
5
- -------------
6
- Likeable is the easiest way to allow your models to be liked by users, just drop a few lines of code into your model and you're good to go.
3
+ You can see the most up-to-date version here: https://github.com/schneems/likeable
7
4
 
8
- ```ruby
5
+ # What is it?
9
6
 
10
- class Comment
11
- include Likeable
7
+ Use Redis to make any Ruby objects Likeable!
12
8
 
13
- # ...
14
- end
15
9
 
16
- class User
17
- include Likeable::UserMethods
10
+ # Why
18
11
 
19
- # ...
20
- end
12
+ We chose Redis because it is screaming fast, and very simple to work with. By using Redis for likeable we take load off of our relational database and speed up individual calls to retrieve information about the "liked" state of an object. If you're not using Redis in production, and don't want to, there are many other great liking/voting libraries out there such as [thumbs up](https://github.com/brady8/thumbs_up).
21
13
 
22
- Likeable.setup do |likeable|
23
- likeable.redis = Redis.new
24
- end
25
-
26
- comment = Comment.find(15)
27
- comment.like_count # => 0
28
- current_user.like!(comment) # => #<Likeable::Like ... >
29
- comment.like_count # => 1
30
- comment.likes # => [#<Likeable::Like ... >]
31
- comment.likes.last.user # => #<User ... >
32
- comment.likes.last.created_at # => Wed Jul 27 19:34:32 -0500 2011
33
-
34
- comment.liked_by?(current_user) # => true
35
-
36
- current_user.all_liked(Comment) # => [#<Comment ...>, ...]
37
-
38
- liked_comment = Likeable.find_by_resource_id("Comment", 15)
39
- liked_comment == comment # => true
40
-
41
- ```
42
-
43
- ## Screencast
44
-
45
- You can view a [screencast of likeable in action on youtube](http://youtu.be/iJoMXUQ33Jw?hd=1). There is also an example [Likeable rails application](https://github.com/schneems/likeable_example) that you can use to follow along.
46
-
47
-
48
-
49
- Setup
50
- =======
51
- Gemfile:
52
-
53
- gem 'likeable'
54
-
55
- Next set up your Redis connection in initializers/likeable.rb:
56
-
57
- ```ruby
58
-
59
- Likeable.setup do |likeable|
60
- likeable.redis = Redis.new
61
- end
62
- ```
63
-
64
- Then add the `Likeable::UserMethods` module to models/user.rb:
65
-
66
- ```ruby
67
-
68
- class User
69
- include Likeable::UserMethods
70
- end
71
- ```
72
-
73
- Finally add `Likeable` module to any model you want to be liked:
74
-
75
- ```ruby
76
-
77
- class Comment
78
- include Likeable
79
- end
80
- ```
81
-
82
- ## Rails Info
83
- If you're using Likeable in Rails this should help you get started
84
-
85
- controllers/likes_controller.rb
86
-
87
- ```ruby
88
-
89
- class LikesController < ApplicationController
90
-
91
- def create
92
- target = Likeable.find_by_resource_id(params[:resource_name], params[:resource_id])
93
- current_user.like!(target)
94
- redirect_to :back, :notice => 'success'
95
- end
96
-
97
- def destroy
98
- target = Likeable.find_by_resource_id(params[:resource_name], params[:resource_id])
99
- current_user.unlike!(target)
100
- redirect_to :back, :notice => 'success'
101
- end
102
- end
103
-
104
- ```
105
-
106
- config/routes.rb
107
-
108
- ```ruby
109
-
110
- delete 'likes/:resource_name/:resource_id' => "likes#destroy", :as => 'like'
111
- post 'likes/:resource_name/:resource_id' => "likes#create", :as => 'like'
112
-
113
- ```
114
-
115
- helpers/like_helper.rb
116
-
117
- ```ruby
118
-
119
- def like_link_for(target)
120
- link_to "like it!!", like_path(:resource_name => target .class, :resource_id => target.id), :method => :post
121
- end
122
-
123
- def unlike_link_for(target)
124
- link_to "unlike it!!", like_path(:resource_name => target.class, :resource_id => target.id), :method => :delete
125
- end
126
-
127
- ```
128
-
129
- Then in any view you can simply call the helper methods to give your user a link
130
-
131
- ```ruby
132
-
133
- <%- if @user.likes? @comment -%>
134
- <%= unlike_link_for @comment %>
135
- <%- else -%>
136
- <%= like_link_for @comment %>
137
- <%- end -%>
138
-
139
-
140
- ```
141
-
142
- Why
143
- ===
144
-
145
- We chose Redis because it is screaming fast, and very simple to work with. By using redis for likeable we take load off of our relational database and speed up individual calls retrieve information about the "liked" state of an object. If you're not using redis in production, and don't want to, there are many other great liking/voting libraries out there such as [thumbs up](https://github.com/brady8/thumbs_up).
146
14
 
147
15
 
148
16
  RedisRed RedisRedi
@@ -172,13 +40,3 @@ Authors
172
40
  =======
173
41
  [Richard Schneeman](http://schneems.com) for [Gowalla](http://gowalla.com) <3
174
42
 
175
-
176
- Contribution
177
- ============
178
-
179
- Fork away. If you want to chat about a feature idea, or a question you can find me on the twitters [@schneems](http://twitter.com/schneems). Put any major changes into feature branches. Make sure all tests stay green, and make sure your changes are covered.
180
-
181
-
182
- licensed under MIT License
183
- Copyright (c) 2011 Schneems. See LICENSE.txt for
184
- further details.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -75,7 +75,7 @@ module Likeable
75
75
 
76
76
 
77
77
  def find_one(klass, id)
78
- @find_one ||= lambda {|klass, ids| klass.where(:id => id).first}
78
+ @find_one ||= lambda {|klass, id| klass.where(:id => id).first}
79
79
  @find_one.call(klass, id)
80
80
  end
81
81
 
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "likeable"
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Schneems"]
12
- s.date = "2011-11-15"
12
+ s.date = "2011-12-17"
13
13
  s.description = "\n Likeable allows you to make your models...well...likeable using redis.\n "
14
14
  s.email = "richard.schneeman@gmail.com"
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: likeable
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 0
10
- version: 0.1.0
9
+ - 1
10
+ version: 0.1.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Schneems
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-11-15 00:00:00 Z
18
+ date: 2011-12-17 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement