mongoid-utils 0.1.11 → 0.1.14

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: 8a20b84e38cda169d5b1cc6f6d48e8b5564b0101
4
- data.tar.gz: 4e9ddbbee973b19d0205833ea940d9f7a50f245f
3
+ metadata.gz: 42d407ec3118c9bce9d61be90de4ca243b8fecd6
4
+ data.tar.gz: f539d3d2bbd8b0003b96b7fbf836eec52e9d4d8f
5
5
  SHA512:
6
- metadata.gz: 3c148643b5d854c958edc58f9bff680b5925f16fac7f06449907e026fd9e46e1462905f5c1468689a60b4f1779c561fab9f969168a76900c65ca292f544491e9
7
- data.tar.gz: eea17775deceb94fedd1f61c1d093e3e16b5ffaff4da4d556874563728a9d21b29375fc58ffdfa72f25469ef9c2df8eaa3969e19056ec4c59854e685f30c8920
6
+ metadata.gz: 741313915b76c0d267f27042c95d9320cca4dc83a936e4e688c67d8fe071725f2f860224e06283b6ff95c1e05a92a160eefc3f1a1fd1d0ea609777ec16a4c049
7
+ data.tar.gz: 8eda1e747ca660dda3a89916681626b8dec5122ac714d76e7e471c2c10395161a48e8ea49cd43d2a58afb7756b527eda98e7e9eeb82a9a734b916b42f527f007
@@ -15,8 +15,8 @@ module Mongoid
15
15
 
16
16
  unless seen
17
17
  hits.create(digest: hit_digest)
18
- self.hits_count = hits_count + 1
19
- self.timeless.save
18
+ self.hits_count = self.hits_count + 1
19
+ self.timeless.save!(validate: false)
20
20
  # self.timeless.update_attribute(:hits_count, hits_count + 1)
21
21
  end
22
22
  end
@@ -23,7 +23,24 @@ module Mongoid
23
23
  end
24
24
 
25
25
  def list_title(list)
26
- lists_hash[list].is_a?(Array) ? lists_hash[list].collect(&:title).join(', ') : lists_hash[list].try(:title)
26
+ # lists_hash[list].is_a?(Array) ? lists_hash[list].collect(&:title).join(', ') : lists_hash[list].try(:title)
27
+ if lists_hash[list].is_a?(Array)
28
+ lists_hash[list].map { |l|
29
+ l.is_a?(Array) ? l.collect(&:title).join(', ') : l.try(:title)
30
+ }
31
+ else
32
+ lists_hash[list].try(:title)
33
+ end
34
+ end
35
+
36
+ def update_lists(new_lists)
37
+ _lists = self.lists
38
+
39
+ new_lists.each do |new_list|
40
+ _lists = _lists.delete_if { |list| list.is_a? new_list.class }
41
+ end
42
+
43
+ self.lists = (_lists + new_lists)
27
44
  end
28
45
  end
29
46
  end
@@ -1,5 +1,5 @@
1
1
  module Mongoid
2
2
  module Utils
3
- VERSION = "0.1.11"
3
+ VERSION = "0.1.14"
4
4
  end
5
5
  end
@@ -6,10 +6,15 @@ module Mongoid
6
6
  included do
7
7
  field :votes_up, type: Integer, default: 0
8
8
  field :votes_down, type: Integer, default: 0
9
+ field :votes_value, type: Integer, default: 0
9
10
 
10
11
  embeds_many :votes, class_name: 'Mongoid::Utils::Votable::Vote'
11
12
 
12
- scope :voted_by, ->(voter) { where('votes.voter_id' => voter.id) }
13
+ scope :voted_by, ->(voter) { where('votes.user_id' => voter.id) }
14
+ scope :votable, -> { order_by(votes_value: :desc) }
15
+
16
+ index votes_value: 1
17
+ index 'votes.user_id' => 1
13
18
  end
14
19
 
15
20
  def voted?(voter)
@@ -42,9 +47,9 @@ module Mongoid
42
47
  self.votes.count
43
48
  end
44
49
 
45
- def votes_value
46
- self.votes_up - self.votes_down
47
- end
50
+ # def votes_value
51
+ # self.votes_up - self.votes_down
52
+ # end
48
53
 
49
54
  module ClassMethods
50
55
  end
@@ -54,8 +59,9 @@ module Mongoid
54
59
  votes_up_change = (vote.value > 0 ? -vote.value : 0) + (value > 0 ? value : 0)
55
60
  votes_down_change = (vote.value < 0 ? vote.value : 0) + (value < 0 ? value.abs : 0)
56
61
 
57
- self.inc(votes_up: votes_up_change)
58
- self.inc(votes_down: votes_down_change)
62
+ self.timeless.inc(votes_up: votes_up_change)
63
+ self.timeless.inc(votes_down: votes_down_change)
64
+ self.timeless.inc(votes_value: votes_up_change - votes_down_change)
59
65
  end
60
66
 
61
67
  class Vote
@@ -65,8 +71,6 @@ module Mongoid
65
71
 
66
72
  belongs_to :user
67
73
  embedded_in :votable
68
-
69
- index voter_id: 1
70
74
  end
71
75
  end
72
76
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michail
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-22 00:00:00.000000000 Z
11
+ date: 2018-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  requirements: []
119
119
  rubyforge_project:
120
- rubygems_version: 2.6.8
120
+ rubygems_version: 2.6.13
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Useful concerns for mongoid ORM for the rails framework. Including commentable,