rating 0.12.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 107d28dc3f0be409a1684eebea163b6dcf6cc57d801f7dcd88bca4f0bcf4f662
4
- data.tar.gz: af591a933ee3bf23720cd054c33968ec9fbba3f21cbd9d117dd1628f0b6cebb5
3
+ metadata.gz: 2d43b5a545fab38d39feb7a46f4d081c4408dd2281f00478996bf989a4f3682d
4
+ data.tar.gz: cfc83ae954ea334ecf0a7cf44b16594d0fd8a3c0fe48cc75034bb662cd555fa7
5
5
  SHA512:
6
- metadata.gz: 3c3dc424ab1155b6a7f6aa309b461015c7d06b2786c172d55b03b29052a3643d098fe78dde4a9c7edf2b564ea324451e5ad1a12373769caa7b6520cb0b5def8d
7
- data.tar.gz: b92eaadfdaa4cca67eca6e3a5550333080541d93b1a48e01dace83bc858969fc718f60123c40353c15bf3ec6c42166b2359d9d82e05b315454a4ca74b91b32be
6
+ metadata.gz: 6a393e04ede36dd77e88023c8ed134e359ad2ead75a96a07e483d46f99fe9ec0c83c9303143dc3fd545902064f8e711c8665de1293259561bec7afd1293ce091
7
+ data.tar.gz: 89e4096c7c2e43b7771e2af9680f8a3fca8753831fc7c4c5685f9fd676fd2694bde65cdbcf816f70150486dd5282141938ecd700ec79d2f9a231b6aadf97eabd
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## v1.0.0
2
+
3
+ ### Break Change
4
+
5
+ - The attributes `estimate` and `average` now is rounded by two decimal numbers;
6
+
7
+ ### Updates
8
+
9
+ - The method `order_by_rating` now receives a hash parameter to avoid scope and so support Ruby 3.2;
10
+
1
11
  ## v0.12.0
2
12
 
3
13
  ### News
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Gem Version](https://badge.fury.io/rb/rating.svg)](https://badge.fury.io/rb/rating)
5
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/cc5efe8b06bc1d5e9e8a/maintainability)](https://codeclimate.com/github/wbotelhos/rating/maintainability)
6
6
  [![codecov](https://codecov.io/gh/wbotelhos/rating/branch/master/graph/badge.svg?token=QJSHUOULEG)](https://codecov.io/gh/wbotelhos/rating)
7
- [![Sponsor](https://img.shields.io/badge/sponsor-%3C3-green)](https://www.patreon.com/wbotelhos)
7
+ [![Sponsor](https://img.shields.io/badge/sponsor-%3C3-green)](https://github.com/sponsors/wbotelhos)
8
8
 
9
9
  A true Bayesian rating system with scope and cache enabled.
10
10
 
@@ -169,7 +169,7 @@ It will return a collection of resource ordered by `estimate desc` as default.
169
169
  The order column and direction can be changed:
170
170
 
171
171
  ```ruby
172
- Article.order_by_rating :average, :asc
172
+ Article.order_by_rating({ column: :average, direction: :asc })
173
173
  ```
174
174
 
175
175
  It will return a collection of resource ordered by `Rating` table data.
@@ -242,7 +242,7 @@ article.rates scope: category_2
242
242
  To order the rating you do the same thing:
243
243
 
244
244
  ```ruby
245
- Article.order_by_rating scope: category_1
245
+ Article.order_by_rating({ scope: category_1 })
246
246
  ```
247
247
 
248
248
  ### Extra Scopes
@@ -3,7 +3,7 @@
3
3
  class CreateRateTable < ActiveRecord::Migration[5.0]
4
4
  def change
5
5
  create_table :rating_rates do |t|
6
- t.decimal :value, default: 0, precision: 25, scale: 16
6
+ t.decimal :value, default: 0, precision: 11, scale: 2
7
7
 
8
8
  t.references :author, index: true, null: false, polymorphic: true
9
9
  t.references :resource, index: true, null: false, polymorphic: true
@@ -3,8 +3,8 @@
3
3
  class CreateRatingTable < ActiveRecord::Migration[5.0]
4
4
  def change
5
5
  create_table :rating_ratings do |t|
6
- t.decimal :average, default: 0, mull: false, precision: 25, scale: 16
7
- t.decimal :estimate, default: 0, mull: false, precision: 25, scale: 16
6
+ t.decimal :average, default: 0, mull: false, precision: 11, scale: 2
7
+ t.decimal :estimate, default: 0, mull: false, precision: 11, scale: 2
8
8
  t.integer :sum, default: 0, mull: false
9
9
  t.integer :total, default: 0, mull: false
10
10
 
@@ -72,7 +72,11 @@ module Rating
72
72
  class_name: '::Rating::Rate',
73
73
  dependent: :destroy
74
74
 
75
- scope :order_by_rating, lambda { |column = :estimate, direction = :desc, scope: nil|
75
+ scope :order_by_rating, lambda { |opts = {}|
76
+ column = opts.fetch(:column, :estimate)
77
+ direction = opts.fetch(:direction, :desc)
78
+ scope = opts[:scope]
79
+
76
80
  includes(:rating_records)
77
81
  .where(Rating.table_name => { scopeable_id: scope&.id, scopeable_type: scope&.class&.base_class&.name })
78
82
  .order("#{Rating.table_name}.#{column} #{direction}")
@@ -43,8 +43,8 @@ module Rating
43
43
  values = values_data(resource, scopeable)
44
44
 
45
45
  {
46
- average: values.rating_avg,
47
- estimate: estimate(averager, values),
46
+ average: values.rating_avg.round(2),
47
+ estimate: estimate(averager, values).round(2),
48
48
  sum: values.rating_sum,
49
49
  total: values.rating_count,
50
50
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rating
4
- VERSION = '0.12.0'
4
+ VERSION = '1.0.0'
5
5
  end
data/lib/rating.rb CHANGED
@@ -8,4 +8,4 @@ require 'rating/models/rating/extension'
8
8
  require 'rating/models/rating/rate'
9
9
  require 'rating/models/rating/rating'
10
10
 
11
- ActiveRecord::Base.include Rating::Extension
11
+ ActiveSupport.on_load(:active_record) { include Rating::Extension }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rating
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Washington Botelho
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-08 00:00:00.000000000 Z
11
+ date: 2023-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: debug
56
+ name: factory_bot_rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: factory_bot_rails
70
+ name: mysql2
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: mysql2
84
+ name: pg
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: pg
98
+ name: pry-byebug
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -219,7 +219,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
219
219
  - !ruby/object:Gem::Version
220
220
  version: '0'
221
221
  requirements: []
222
- rubygems_version: 3.3.12
222
+ rubygems_version: 3.4.6
223
223
  signing_key:
224
224
  specification_version: 4
225
225
  summary: A true Bayesian rating system with scope and cache enabled.