ratable 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0b37b427f57776006d941b8f962e0ac53c332972
4
- data.tar.gz: 4784df61824db2de0351693663283bd173713e82
3
+ metadata.gz: 0b73a6b2a07a0e7148f91bdfa503d6d849e0621e
4
+ data.tar.gz: 1f5ee31f7d742e84326135d5c4042be6cfe0fc5c
5
5
  SHA512:
6
- metadata.gz: 0bc3c2714db3e79fba8b448776172340c0717b17fc7bcf59ea5942fab553456f4f5458cc4b16c16eaad6d9cef22de8de09b38c93f3651b6a72ea46dcf5c2fa37
7
- data.tar.gz: bc620147f939dbc11733389ea429f6b5f3c9c0276fce72d54a64d991ca3caaf0780caf12ab800df9610092d37eb82dd17a812d037151ab6b6a4cb1d9a1668f2f
6
+ metadata.gz: 35e0271f3f1855f1fb22a53e546f97554c9ca98367d25390b478fa11119c96887d629cb5befc955ba39a3261ba8a8b8bf4b2ee1fc62f494432568819f2bfff62
7
+ data.tar.gz: 5e4383b223bf6cf7ae9a988abb0d7226b9f96ddf0a8de514a3a0f00d5b5bf76a4e1f170b001ab3ff78e8fa9a72a464a8f205fc0300e4e0665a1bb1a775dd33e8
@@ -1,5 +1,4 @@
1
- //= require jquery
2
- //= require_tree ../../../vendor/assets/javascripts
1
+ //= require jquery.raty.js
3
2
  (function($){
4
3
  $.fn.raty.defaults.starHalf = '<%= image_path('star-half.png') %>';
5
4
  $.fn.raty.defaults.starOn = '<%= image_path('star-on.png') %>';
@@ -0,0 +1,16 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into ratable.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require jquery.raty.css
14
+ *= require_tree .
15
+ *= require_self
16
+ */
@@ -2,66 +2,41 @@ module Ratable
2
2
  module Models
3
3
  module Ratee
4
4
  extend ActiveSupport::Concern
5
- extend Ratable::ActiveRecordExtension
6
5
 
7
6
  attr_reader :has_one
8
7
 
9
8
  module ActiveRecordExtension
10
9
  def acts_as_ratee(options={has_one: false})
11
- throw "To make a model the rater and the ratee use `acts_as_ratee_and_rater`" if acts_like_rater?
10
+ raise "To make a model the rater and the ratee use `acts_as_ratee_and_rater`" if acts_like_rater?
12
11
  @has_one = options[:has_one]
13
12
  include Ratee
14
13
  end
15
14
  end
16
15
 
17
16
  included do
18
- unless acts_like_rater?
19
- if @has_one
20
- has_one :rating, class_name: 'Ratable::Rating', dependent: :destroy, as: :ratee
21
- else
22
- has_many :ratings, class_name: 'Ratable::Rating', dependent: :destroy, as: :ratee
23
- end
17
+ if @has_one
18
+ has_one :rating, class_name: 'Ratable::Rating', dependent: :destroy, as: :ratee
24
19
  else
25
- if @has_one
26
- has_one :ratee_rating, class_name: 'Ratable::Rating', dependent: :destroy, as: :ratee
27
- else
28
- has_many :ratee_ratings, class_name: 'Ratable::Rating', dependent: :destroy, as: :ratee
29
- end
20
+ has_many :ratings, class_name: 'Ratable::Rating', dependent: :destroy, as: :ratee
30
21
  end
31
22
  end
32
23
 
33
24
  def raters
34
- unless acts_like_rater?
35
- if @has_one
36
- rating.rater
37
- else
38
- ratings.includes(:rater).collect { |rating| rating.rater }
39
- end
25
+ if @has_one
26
+ rating.rater
40
27
  else
41
- if @has_one
42
- ratee_rating.rater
43
- else
44
- ratee_ratings.includes(:rater).collect { |rating| rating.rater }
45
- end
28
+ ratings.includes(:rater).collect { |rating| rating.rater }
46
29
  end
47
30
  end
48
31
 
49
- # def rate(options={})
50
- # options.reject! { |k| k == :ratee }
51
- # unless acts_like_rater?
52
- # if @has_one
53
- # self.rating.create(options)
54
- # else
55
- # self.ratings.create(options)
56
- # end
57
- # else
58
- # if @has_one
59
- # self.ratee_rating.create(options)
60
- # else
61
- # self.ratee_ratings.create(options)
62
- # end
63
- # end
64
- # end
32
+ def rate(options={})
33
+ options.reject! { |k| k == :ratee }
34
+ if @has_one
35
+ self.rating.create(options)
36
+ else
37
+ self.ratings.create(options)
38
+ end
39
+ end
65
40
 
66
41
  end
67
42
  end
@@ -2,7 +2,6 @@ module Ratable
2
2
  module Models
3
3
  module RateeRater
4
4
  extend ActiveSupport::Concern
5
- extend Ratable::ActiveRecordExtension
6
5
 
7
6
  attr_reader :has_one_ratee, :has_one_rater
8
7
 
@@ -7,7 +7,7 @@ module Ratable
7
7
 
8
8
  module ActiveRecordExtension
9
9
  def acts_as_rater(options={has_one: false})
10
- throw "To make a model the rater and the ratee use `acts_as_ratee_and_rater`" if acts_like_ratee?
10
+ raise "To make a model the rater and the ratee use `acts_as_ratee_and_rater`" if acts_like_ratee?
11
11
  @has_one = options[:has_one]
12
12
  include Rater
13
13
  end
@@ -1,3 +1,3 @@
1
1
  module Ratable
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
@@ -4,5 +4,6 @@ class User < ActiveRecord::Base
4
4
  devise :database_authenticatable, :registerable,
5
5
  :recoverable, :rememberable, :trackable, :validatable
6
6
 
7
- acts_as_ratee_and_rater
7
+ acts_as_ratee
8
+ acts_as_rater
8
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ratable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - François Bélanger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-25 00:00:00.000000000 Z
11
+ date: 2016-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -120,7 +120,7 @@ files:
120
120
  - README.rdoc
121
121
  - Rakefile
122
122
  - app/assets/javascripts/ratable.js.erb
123
- - app/assets/javascripts/ratings.js
123
+ - app/assets/stylesheets/ratable.scss
124
124
  - app/models/ratable/rating.rb
125
125
  - app/views/ratable/ratings/_rating.html.erb
126
126
  - db/migrate/20160418175804_create_ratable_ratings.rb
@@ -1,10 +0,0 @@
1
- $(function() {
2
- $('.rating').each(function() {
3
- $this = $(this);
4
- $this.raty({
5
- score: $this.data('rating'),
6
- scoreName: 'star',
7
- space: true
8
- });
9
- });
10
- });