thumbit 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README +13 -0
- data/Rakefile +23 -0
- data/init.rb +2 -0
- data/install.rb +1 -0
- data/lib/app/models/like.rb +4 -0
- data/lib/app/models/liking.rb +6 -0
- data/lib/generators/thumbit/USAGE +8 -0
- data/lib/generators/thumbit/templates/create_likes_and_likings.rb +19 -0
- data/lib/generators/thumbit/templates/like.rb +4 -0
- data/lib/generators/thumbit/templates/liking.rb +6 -0
- data/lib/generators/thumbit/thumbit_generator.rb +15 -0
- data/lib/thumbit/acts_as_likeable.rb +48 -0
- data/lib/thumbit/version.rb +3 -0
- data/lib/thumbit.rb +10 -0
- data/rails/init.rb +1 -0
- data/test/acts_as_likeable_test.rb +8 -0
- data/test/test_helper.rb +3 -0
- data/test/thumbit_test.rb +8 -0
- data/thumbit.gemspec +21 -0
- data/uninstall.rb +1 -0
- metadata +88 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rake'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rake/rdoctask'
|
4
|
+
|
5
|
+
desc 'Default: run unit tests.'
|
6
|
+
task :default => :test
|
7
|
+
|
8
|
+
desc 'Test the acts_as_likeable plugin.'
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'lib'
|
11
|
+
t.libs << 'test'
|
12
|
+
t.pattern = 'test/**/*_test.rb'
|
13
|
+
t.verbose = true
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Generate documentation for the acts_as_likeable plugin.'
|
17
|
+
Rake::RDocTask.new(:rdoc) do |rdoc|
|
18
|
+
rdoc.rdoc_dir = 'rdoc'
|
19
|
+
rdoc.title = 'ActsAsLikeable'
|
20
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
21
|
+
rdoc.rdoc_files.include('README')
|
22
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
23
|
+
end
|
data/init.rb
ADDED
data/install.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Install hook code here
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class CreateLikesAndLikings < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :likings do |t|
|
4
|
+
t.belongs_to :user
|
5
|
+
t.belongs_to :like
|
6
|
+
t.belongs_to :likeable, :polymorphic => true
|
7
|
+
t.timestamps
|
8
|
+
end
|
9
|
+
create_table :likes do |t|
|
10
|
+
t.integer :likes, :default => 0
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.down
|
16
|
+
drop_table :likings
|
17
|
+
drop_table :likes
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class ThumbitGenerator < Rails::Generators::Base
|
2
|
+
include Rails::Generators::Migration
|
3
|
+
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
def self.next_migration_number(path)
|
7
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
8
|
+
end
|
9
|
+
|
10
|
+
def create_model_file
|
11
|
+
template "like.rb", "app/models/like.rb"
|
12
|
+
template "liking.rb", "app/models/liking.rb"
|
13
|
+
migration_template "create_likes_and_likings.rb", "db/migrate/create_likes_and_likings.rb"
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
|
2
|
+
module ActsAsLikeable
|
3
|
+
def self.included base
|
4
|
+
base.send :extend, ClassMethods
|
5
|
+
end
|
6
|
+
|
7
|
+
module ClassMethods
|
8
|
+
def acts_as_likeable options = {}
|
9
|
+
has_many :likings, :as => :likeable, :dependent => :destroy
|
10
|
+
has_many :likes, :through => :likings
|
11
|
+
send :extend, SingletonMethods
|
12
|
+
send :include, InstanceMethods
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module SingletonMethods
|
17
|
+
def find_likes_for obj
|
18
|
+
likeable = self.base_class.name
|
19
|
+
Liking.find(:all, :conditions => [ "likeable_type = ? and likeable_id = ?", likeable, obj.id ]).count
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_likes_by user
|
23
|
+
likeable = self.base_class.name
|
24
|
+
Liking.where(["user_id = ? and likeable_type = ?", user.id, likeable]).count
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
module InstanceMethods
|
29
|
+
def like_it user_obj
|
30
|
+
like = Like.create :likes => 1
|
31
|
+
#RAILS_DEFAULT_LOGGER.info(like)
|
32
|
+
likeable = Liking.new
|
33
|
+
likeable.user_id = user_obj.id
|
34
|
+
likeable.likeable_id = self.id
|
35
|
+
likeable.likeable_type = self.class
|
36
|
+
likeable.like_id = like.id
|
37
|
+
#RAILS_DEFAULT_LOGGER.info(likeable)
|
38
|
+
likeable.save
|
39
|
+
end
|
40
|
+
|
41
|
+
def likes_count
|
42
|
+
self.likes.size
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
ActiveRecord::Base.send :include, ActsAsLikeable
|
data/lib/thumbit.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# Thumbit
|
2
|
+
|
3
|
+
require "thumbit/acts_as_likeable"
|
4
|
+
|
5
|
+
%w{ models controllers helpers }.each do |dir|
|
6
|
+
path = File.join(File.dirname(__FILE__), 'app', dir)
|
7
|
+
$LOAD_PATH << path
|
8
|
+
ActiveSupport::Dependencies.autoload_paths << path
|
9
|
+
ActiveSupport::Dependencies.autoload_once_paths.delete(path)
|
10
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "thumbit"
|
data/test/test_helper.rb
ADDED
data/thumbit.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "thumbit/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "thumbit"
|
7
|
+
s.version = Thumbit::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Madhusudhan Srinivasa"]
|
10
|
+
s.email = ["madhums8@gmil.com"]
|
11
|
+
s.homepage = "http://rubygems.org/gems/thumbit"
|
12
|
+
s.summary = %q{A simple 'like' plugin/gem for rails}
|
13
|
+
s.description = %q{A simple 'like' plugin/gem for rails}
|
14
|
+
|
15
|
+
s.rubyforge_project = "thumbit"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
data/uninstall.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Uninstall hook code here
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: thumbit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Madhusudhan Srinivasa
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-12 00:00:00 +05:30
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: A simple 'like' plugin/gem for rails
|
23
|
+
email:
|
24
|
+
- madhums8@gmil.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- MIT-LICENSE
|
33
|
+
- README
|
34
|
+
- Rakefile
|
35
|
+
- init.rb
|
36
|
+
- install.rb
|
37
|
+
- lib/app/models/like.rb
|
38
|
+
- lib/app/models/liking.rb
|
39
|
+
- lib/generators/thumbit/USAGE
|
40
|
+
- lib/generators/thumbit/templates/create_likes_and_likings.rb
|
41
|
+
- lib/generators/thumbit/templates/like.rb
|
42
|
+
- lib/generators/thumbit/templates/liking.rb
|
43
|
+
- lib/generators/thumbit/thumbit_generator.rb
|
44
|
+
- lib/thumbit.rb
|
45
|
+
- lib/thumbit/acts_as_likeable.rb
|
46
|
+
- lib/thumbit/version.rb
|
47
|
+
- rails/init.rb
|
48
|
+
- test/acts_as_likeable_test.rb
|
49
|
+
- test/test_helper.rb
|
50
|
+
- test/thumbit_test.rb
|
51
|
+
- thumbit.gemspec
|
52
|
+
- uninstall.rb
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://rubygems.org/gems/thumbit
|
55
|
+
licenses: []
|
56
|
+
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
hash: 3
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
requirements: []
|
81
|
+
|
82
|
+
rubyforge_project: thumbit
|
83
|
+
rubygems_version: 1.3.7
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: A simple 'like' plugin/gem for rails
|
87
|
+
test_files: []
|
88
|
+
|