voteable_rockstar 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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/voteable_rockstar.rb +51 -0
  3. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 03c3e0ef744652f931a3f44372b85b7e8dc96ac4
4
+ data.tar.gz: a6207a66085f6d808d855fb59ab0b781fa333086
5
+ SHA512:
6
+ metadata.gz: adf26217a4196cb55764647e82b52019bf39cec754439100e46a6f6bdb30fd18947c76a1d37904c6d81565e95b4a7d1b7956ed5fc3e467e85d2058f63f05db87
7
+ data.tar.gz: a07ef1c76fa2fd8713291fa20ad84d9b25d6c8fcbfc29e05fb74e014d7f38edf191a7e7ecbe0d33aa55fae738c82733fa78497f764149410731d340e487bfe52
@@ -0,0 +1,51 @@
1
+ # using concerns (it's a rails thing)
2
+ module Voteable
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ has_many :votes, as: :voteable
7
+ end
8
+
9
+ def diff_votes
10
+ self.up_votes - self.down_votes
11
+ end
12
+
13
+ def up_votes
14
+ self.votes.where(vote: true).size
15
+ end
16
+
17
+ def down_votes
18
+ self.votes.where(vote: false).size
19
+ end
20
+ end
21
+
22
+ # normal metaprogramming
23
+ # module Voteable
24
+ # def self.included(base)
25
+ # base.send(:include, InstanceMethods)
26
+ # base.extend ClassMethods
27
+ # base.class_eval do
28
+ # associate_votes
29
+ # end
30
+ # end
31
+
32
+ # module InstanceMethods
33
+ # def diff_votes
34
+ # self.up_votes - self.down_votes
35
+ # end
36
+
37
+ # def up_votes
38
+ # self.votes.where(vote: true).size
39
+ # end
40
+
41
+ # def down_votes
42
+ # self.votes.where(vote: false).size
43
+ # end
44
+ # end
45
+
46
+ # module ClassMethods
47
+ # def associate_votes
48
+ # has_many :votes, as: :voteable
49
+ # end
50
+ # end
51
+ # end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: voteable_rockstar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Mentele
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Include on objects to add voting behavior
14
+ email: michaelrmentele@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/voteable_rockstar.rb
20
+ homepage: https://github.com/MichaelrMentele/voteable-rockstar.git
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.4.6
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: A voting gem that adds up vote counting, down vote counting, a difference
44
+ between them and a polymorphic association as voteable.
45
+ test_files: []