voteable_ryan 0.0.0
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 +7 -0
- data/lib/voteable_ryan.rb +61 -0
- metadata +44 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: efda458e8586dabb9b61843a3d5b77d61978507f
|
|
4
|
+
data.tar.gz: ba5606bf3bd6327c3718e9513e50bddcb05c854b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1971a02c77bdec5d22fe9117a9c20b0c7a96b27ac29c19dad7dd771171fe0e801494203948d7f4d7c3b58ae279bf0096609fc3abcf1aa3a5efdf6668741ab466
|
|
7
|
+
data.tar.gz: d283022cdb1b0082dba427cfe2c04477c92ae2ba4ed93676e4ec8e1cf81d2deccdbc138284ab90ea3948b419e7738fb9a8ef84f1ff50784c70fb76fcd0e6bf66
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Usinfg Concerns
|
|
2
|
+
module Voteable
|
|
3
|
+
extend ActiveSupport::Concern
|
|
4
|
+
|
|
5
|
+
# When we include this module the included will be fired
|
|
6
|
+
included do
|
|
7
|
+
# has_many is a class method inheriented from ActiveRecord::Base
|
|
8
|
+
has_many :votes, as: :voteable
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def total_votes
|
|
12
|
+
self.up_votes - self.down_votes
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def up_votes
|
|
16
|
+
self.votes.where(vote: true).size
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def down_votes
|
|
20
|
+
self.votes.where(vote: false).size
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
=begin
|
|
29
|
+
# Using normal Metaprogramming
|
|
30
|
+
module Voteable
|
|
31
|
+
# When we include this module the include will be fired
|
|
32
|
+
def self.included(base)
|
|
33
|
+
base.send(:include, InstanceMethods)
|
|
34
|
+
base.extend ClassMethods
|
|
35
|
+
base.class_eval do
|
|
36
|
+
my_class_method
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
module InstanceMethods
|
|
41
|
+
def total_votes
|
|
42
|
+
self.up_votes - self.down_votes
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def up_votes
|
|
46
|
+
self.votes.where(vote: true).size
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def down_votes
|
|
50
|
+
self.votes.where(vote: false).size
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
module ClassMethods
|
|
55
|
+
def my_class_method
|
|
56
|
+
#puts "This is my Class Method"
|
|
57
|
+
has_many :votes, as: :voteable
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
=end
|
metadata
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: voteable_ryan
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ryan Yang
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2014-01-01 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: The best voting gem ever.
|
|
14
|
+
email: hiphubryan@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/voteable_ryan.rb
|
|
20
|
+
homepage: https://github.com/ryanyangtw/voteable-gem
|
|
21
|
+
licenses: []
|
|
22
|
+
metadata: {}
|
|
23
|
+
post_install_message:
|
|
24
|
+
rdoc_options: []
|
|
25
|
+
require_paths:
|
|
26
|
+
- lib
|
|
27
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
28
|
+
requirements:
|
|
29
|
+
- - ">="
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '0'
|
|
32
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
33
|
+
requirements:
|
|
34
|
+
- - ">="
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '0'
|
|
37
|
+
requirements: []
|
|
38
|
+
rubyforge_project:
|
|
39
|
+
rubygems_version: 2.2.2
|
|
40
|
+
signing_key:
|
|
41
|
+
specification_version: 4
|
|
42
|
+
summary: A voting gem
|
|
43
|
+
test_files: []
|
|
44
|
+
has_rdoc:
|