dm-is-voteable 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/dm-is-voteable.gemspec +2 -2
- data/lib/dm-is-voteable/is/models/vote.rb +8 -7
- data/lib/dm-is-voteable/is/voteable.rb +5 -2
- metadata +3 -3
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('dm-is-voteable', '0.0.
|
5
|
+
Echoe.new('dm-is-voteable', '0.0.4') do |p|
|
6
6
|
p.description = "Makes a model voteable"
|
7
7
|
p.url = "http://github.com/brianp/dm-is-voteable"
|
8
8
|
p.author = "Brian Pearce"
|
data/dm-is-voteable.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{dm-is-voteable}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.4"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Brian Pearce"]
|
9
|
-
s.date = %q{2010-10-
|
9
|
+
s.date = %q{2010-10-12}
|
10
10
|
s.description = %q{Makes a model voteable}
|
11
11
|
s.email = %q{brian.o.pearce@gmail.com}
|
12
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,15 +13,16 @@ class Vote
|
|
13
13
|
property :updated_at, DateTime, :lazy => true
|
14
14
|
property :updated_on, Date, :lazy => true
|
15
15
|
|
16
|
-
validates_with_method :
|
16
|
+
validates_with_method :no_vote_in_x_days
|
17
17
|
|
18
|
-
def
|
19
|
-
|
18
|
+
def no_vote_in_x_days
|
19
|
+
if Vote.respond_to?('x_days')
|
20
|
+
return Vote.count(:voter => voter, :created_on.gt => Vote.x_days.days.ago) == 0
|
21
|
+
else
|
22
|
+
return true
|
23
|
+
end
|
20
24
|
end
|
21
|
-
|
25
|
+
|
22
26
|
# belongs_to :voteable, :voteable_id
|
23
|
-
|
24
|
-
# Uncomment this to limit users to a single vote.
|
25
|
-
# validates_uniqueness_of :voter
|
26
27
|
|
27
28
|
end
|
@@ -5,6 +5,11 @@ module DataMapper
|
|
5
5
|
def is_voteable(options = {}, &block)
|
6
6
|
has n, :votes, :as => :voteable, :child_key => [ :voteable_id ]
|
7
7
|
|
8
|
+
if !options[:every_x_days].nil?
|
9
|
+
Vote.instance_eval { @@x_days = 0; def x_days; @@x_days; end; def x_days=(value); @@x_days = (value); end }
|
10
|
+
Vote.x_days = options[:every_x_days]
|
11
|
+
end
|
12
|
+
|
8
13
|
include DataMapper::Is::Voteable::InstanceMethods
|
9
14
|
extend DataMapper::Is::Voteable::SingletonMethods
|
10
15
|
end
|
@@ -15,8 +20,6 @@ module DataMapper
|
|
15
20
|
|
16
21
|
module InstanceMethods
|
17
22
|
def vote(voter)
|
18
|
-
# puts "HERE:"
|
19
|
-
# puts env.inspect
|
20
23
|
vote = Vote.new(:voteable_id => self.id, :voteable_type => self.class, :voter => voter)
|
21
24
|
vote.save
|
22
25
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Brian Pearce
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-10-
|
17
|
+
date: 2010-10-12 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|