votable_rw 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/votable_rw.rb +22 -0
  3. metadata +43 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b577e69e1cc2f6aef2cb90d26f498387163e7578
4
+ data.tar.gz: c2465a8f13aa14d0f267571bd348f1d6736a80d0
5
+ SHA512:
6
+ metadata.gz: 4c42761cdd34eb47a1330c831ec6cf6a99233fae6032822dd756be3c4585b38147d6a639354f8822dda1144c29d582801936b2ddb510ad6259f41c1adb889aa9
7
+ data.tar.gz: d17dee8874e0564b83d370f2158cf40605ca2301e6fdd91349b940140535a1c20f4ac0dbf3f90f27cedbc19a50581e44df8af5d0ac39435e4a5d2a899f8586cb
data/lib/votable_rw.rb ADDED
@@ -0,0 +1,22 @@
1
+ module Votable
2
+ # usinf rails 4 active support to make the instance variable in the module
3
+ # be able to accessed if the module is included
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ has_many :votes, as: :votable
8
+ end
9
+
10
+ def total_votes
11
+ up_votes - down_votes
12
+ end
13
+
14
+ def up_votes
15
+ self.votes.where(vote: true).size
16
+ end
17
+
18
+ def down_votes
19
+ self.votes.where(vote: false).size
20
+ end
21
+
22
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: votable_rw
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ravi L.W. Wu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Simple voting mechanism for quick project
14
+ email: raviwu@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/votable_rw.rb
20
+ homepage: http://github.com
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.4.6
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: A simple voting gem
43
+ test_files: []