voteable-dk 0.0.2 → 0.0.3
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.
- checksums.yaml +4 -4
- data/lib/voteable-dk.rb +18 -22
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7fc3e95ee08ab3c564e36dbdbb9745802836148
|
4
|
+
data.tar.gz: 57695cfd53263589f1863ae38668358a43a64831
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e811a884f915b49d4882944ce4b69f68c15e3e358b19f4910592e2d02afb2e4403f3ea82d17a5ad4d3e7af345a6d62e306ef43c7db344091e6cb14722967c2e
|
7
|
+
data.tar.gz: 1f87ca002e52001bd780b4232f8ad30720e5e7f7063d5c839d380bc62dd7c8278ae8b74acd0ea3c260a7de21f487f6b1c2d8b0c6965105c74f617604fb0b2349
|
data/lib/voteable-dk.rb
CHANGED
@@ -1,27 +1,23 @@
|
|
1
1
|
# Assumes has_many votes association, with a boolean 'vote' column
|
2
2
|
module VoteableDk
|
3
|
-
def self.
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
def self.included(base)
|
4
|
+
base.send(:include, InstanceMethods)
|
5
|
+
base.extend ClassMethods
|
6
|
+
base.class_eval do
|
7
|
+
my_class_method
|
8
|
+
end
|
9
|
+
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
def my_instance_method
|
17
|
-
puts "module's instance method"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
module ClassMethods
|
22
|
-
def my_class_method
|
23
|
-
has_many :votes, as: :voteable
|
24
|
-
end
|
25
|
-
end
|
11
|
+
module InstanceMethods
|
12
|
+
def total_votes
|
13
|
+
self.votes.where(vote: true).size - self.votes.where(vote: false).size
|
14
|
+
end
|
15
|
+
end
|
26
16
|
|
17
|
+
module ClassMethods
|
18
|
+
def my_class_method
|
19
|
+
has_many :votes, as: :voteable
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
27
23
|
end
|