dm-is-voteable 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
File without changes
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Brian Pearce
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/Manifest ADDED
@@ -0,0 +1,10 @@
1
+ CHANGELOG
2
+ MIT-LICENSE
3
+ Manifest
4
+ README.rdoc
5
+ Rakefile
6
+ dm-is-voteable.gemspec
7
+ init.rb
8
+ lib/dm-is-voteable.rb
9
+ lib/dm-is-voteable/is/models/vote.rb
10
+ lib/dm-is-voteable/is/voteable.rb
data/README.rdoc ADDED
@@ -0,0 +1,43 @@
1
+ = dm-is-voteable
2
+
3
+ A DataMapper compatible "anonymous" voting plugin. Can track votes by IP so a user may only submit a single vote.
4
+
5
+ < Rails 3 not tested.
6
+
7
+ = Installation
8
+ To install as a gem add the following line to your gem file.
9
+ gem "dm-is-voteable"
10
+
11
+ Then run:
12
+ $ bundle install
13
+
14
+ And build the required DB tables:
15
+ $ rake db:auto_update
16
+
17
+ = Example
18
+
19
+ Add:
20
+
21
+ is :voteable
22
+
23
+ To any model and gain the power of the vote method.
24
+
25
+ class Movie
26
+ include DataMapper::Resource
27
+
28
+ property :id, Serial
29
+
30
+ is :voteable
31
+
32
+ property :title, String, :required => true
33
+ end
34
+
35
+ Vote for the Model by calling:
36
+ Model.vote
37
+
38
+ Allow only a single vote per user by sending the request IP with the vote:
39
+
40
+ user_ip = request.env['REMOTE_ADDR']
41
+ Model.vote(user_ip)
42
+
43
+ Copyright (c) 2010 Brian Pearce, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new('dm-is-voteable', '0.0.1') do |p|
6
+ p.description = "Makes a model voteable"
7
+ p.url = "http://github.com/brianp/dm-is-voteable"
8
+ p.author = "Brian Pearce"
9
+ p.email = "brian.o.pearce@gmail.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{dm-is-voteable}
5
+ s.version = "0.0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Brian Pearce"]
9
+ s.date = %q{2010-10-04}
10
+ s.description = %q{Makes a model voteable}
11
+ s.email = %q{brian.o.pearce@gmail.com}
12
+ s.extra_rdoc_files = ["CHANGELOG", "README.rdoc", "lib/dm-is-voteable.rb", "lib/dm-is-voteable/is/models/vote.rb", "lib/dm-is-voteable/is/voteable.rb"]
13
+ s.files = ["CHANGELOG", "MIT-LICENSE", "Manifest", "README.rdoc", "Rakefile", "dm-is-voteable.gemspec", "init.rb", "lib/dm-is-voteable.rb", "lib/dm-is-voteable/is/models/vote.rb", "lib/dm-is-voteable/is/voteable.rb"]
14
+ s.homepage = %q{http://github.com/brianp/dm-is-voteable}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Dm-is-voteable", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{dm-is-voteable}
18
+ s.rubygems_version = %q{1.3.7}
19
+ s.summary = %q{Makes a model voteable}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'dm-is-voteable'
@@ -0,0 +1,27 @@
1
+ class Vote
2
+
3
+ include DataMapper::Resource
4
+
5
+ property :id, Serial
6
+
7
+ property :voter, IPAddress
8
+ property :voteable_id, Integer, :required => true
9
+ property :voteable_type, String, :required => true
10
+
11
+ property :created_at, DateTime, :lazy => true
12
+ property :created_on, Date, :lazy => true
13
+ property :updated_at, DateTime, :lazy => true
14
+ property :updated_on, Date, :lazy => true
15
+
16
+ validates_with_method :no_vote_in_3_days
17
+
18
+ def no_vote_in_3_days
19
+ Vote.count(:voter => voter, :created_on.gt => 2.days.ago) == 0
20
+ end
21
+
22
+ # belongs_to :voteable, :voteable_id
23
+
24
+ # Uncomment this to limit users to a single vote.
25
+ # validates_uniqueness_of :voter
26
+
27
+ end
@@ -0,0 +1,35 @@
1
+ module DataMapper
2
+ module Is #:nodoc:
3
+ module Voteable #:nodoc:
4
+
5
+ def is_voteable(options = {}, &block)
6
+ has n, :votes, :as => :voteable, :child_key => [ :voteable_id ]
7
+
8
+ include DataMapper::Is::Voteable::InstanceMethods
9
+ extend DataMapper::Is::Voteable::SingletonMethods
10
+ end
11
+
12
+ module SingletonMethods
13
+ # Add class methods here
14
+ end
15
+
16
+ module InstanceMethods
17
+ def vote(voter)
18
+ # puts "HERE:"
19
+ # puts env.inspect
20
+ vote = Vote.new(:voteable_id => self.id, :voteable_type => self.class, :voter => voter)
21
+ vote.save
22
+ end
23
+
24
+ # def tally_votes(options = {})
25
+ # self.votes.count
26
+ # end
27
+
28
+ def tally_votes(options = {})
29
+ count = Vote.count(:conditions => ["voteable_id = ?", self.id])
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ require 'dm-is-voteable/is/voteable'
2
+ require 'dm-is-voteable/is/models/vote'
3
+
4
+ DataMapper::Model.append_extensions DataMapper::Is::Voteable
5
+ # RAILS_DEFAULT_LOGGER.info "** vote_on: initialized properly."
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dm-is-voteable
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
+ - Brian Pearce
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-04 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: Makes a model voteable
23
+ email: brian.o.pearce@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - CHANGELOG
30
+ - README.rdoc
31
+ - lib/dm-is-voteable.rb
32
+ - lib/dm-is-voteable/is/models/vote.rb
33
+ - lib/dm-is-voteable/is/voteable.rb
34
+ files:
35
+ - CHANGELOG
36
+ - MIT-LICENSE
37
+ - Manifest
38
+ - README.rdoc
39
+ - Rakefile
40
+ - dm-is-voteable.gemspec
41
+ - init.rb
42
+ - lib/dm-is-voteable.rb
43
+ - lib/dm-is-voteable/is/models/vote.rb
44
+ - lib/dm-is-voteable/is/voteable.rb
45
+ has_rdoc: true
46
+ homepage: http://github.com/brianp/dm-is-voteable
47
+ licenses: []
48
+
49
+ post_install_message:
50
+ rdoc_options:
51
+ - --line-numbers
52
+ - --inline-source
53
+ - --title
54
+ - Dm-is-voteable
55
+ - --main
56
+ - README.rdoc
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ hash: 3
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ hash: 11
74
+ segments:
75
+ - 1
76
+ - 2
77
+ version: "1.2"
78
+ requirements: []
79
+
80
+ rubyforge_project: dm-is-voteable
81
+ rubygems_version: 1.3.7
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Makes a model voteable
85
+ test_files: []
86
+