unread-mongoid 0.0.1 → 0.0.2

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
  SHA1:
3
- metadata.gz: 0de8df9d08d0700507b4e45252f7dfa78328f19f
4
- data.tar.gz: 028872b091dedaf7bad1c803f38cad621d2ef681
3
+ metadata.gz: fff81cda9ab35182ca6e221415467c3b36df486d
4
+ data.tar.gz: 58fbf8f25b5b3c06c858c0e68017b1ad8a50e202
5
5
  SHA512:
6
- metadata.gz: 38fc2a6c00adb96aa4972014bd3b1fbb94189c64f12a348ccf042674f26f752f8503a474462149796f38bb3926374d4ce1560c3d1ee82b3f868db728eca6f918
7
- data.tar.gz: 3a0b7e197a0d142869ae2ccce5412a23de724f26bd9eb0d4ab83dec630994978087ceb2b385c6e90758b42704f35154aef73a8ad33772a7e47ecef5db60a5ad4
6
+ metadata.gz: 0d9528baf77bf362f20bf016193cd8ccf631fac799c2984353c400cff8e478b5aefb0983659d32f1cc69a55fbbaf6cdbe7496d69e2f01abd6abd91a118e0436e
7
+ data.tar.gz: 6a69cc802404a2b5b4708046de7bd074903e2fe0d2258c11339ab312b68d01a2c9790eaec163f823d8f77c3d514f768c33b5b8585914e7e01164abfc3e4a931b
data/README.md CHANGED
@@ -4,7 +4,7 @@ Unread-Mongoid
4
4
  Ruby gem to manage read/unread status of Mongoid objects.
5
5
 
6
6
  ## Credit
7
- First and foremost this is a fork of [Unread](https://github.com/ledermann/unread) by [Georg Ledermann](http://www.georg-ledermann.de). If you don't have to use Mongo for this I highly reccoment you use his gem, this is a task much better suited to a relational db, I had to remove some features to make it work for Mongoid.
7
+ First and foremost this is a fork of [Unread](https://github.com/ledermann/unread) by [Georg Ledermann](http://www.georg-ledermann.de). If you don't have to use Mongo for this I highly reccoment you use his gem, this is a task much better suited to a relational db.
8
8
 
9
9
  ## Features
10
10
 
data/changelog.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.0.2 - 2013-08-01
4
+
5
+ * ```unread_by?``` now checks against the ```readable_options[:on]``` timestamp. (Set on each ```ReadMark``` by an ```after_save``` callback)
6
+
3
7
  ## 0.0.1 - 2013-07-31
4
8
 
5
9
  * Converted to from Unread
@@ -28,6 +28,14 @@ module UnreadMongoid
28
28
 
29
29
  has_many :read_marks, :as => :readable, :dependent => :delete_all
30
30
 
31
+ # :(
32
+ after_save do |doc|
33
+ doc.read_marks.each do |mark|
34
+ mark.readable_timestamp = doc.readable_timestamp
35
+ mark.save!
36
+ end
37
+ end
38
+
31
39
  ReadMark.readable_classes ||= []
32
40
  ReadMark.readable_classes << self unless ReadMark.readable_classes.include?(self)
33
41
 
@@ -2,6 +2,7 @@ class ReadMark
2
2
  include Mongoid::Document
3
3
 
4
4
  field :timestamp, type: Time
5
+ field :readable_timestamp, type: Time, default: -> { readable.readable_timestamp if readable }
5
6
 
6
7
  belongs_to :readable, :polymorphic => true
7
8
  belongs_to :user
@@ -94,6 +94,10 @@ module UnreadMongoid
94
94
  end
95
95
 
96
96
  module InstanceMethods
97
+ def readable_timestamp
98
+ self.send(readable_options[:on]).to_s(:db)
99
+ end
100
+
97
101
  def unread?(user)
98
102
  self.class.unread_by(user).and(_id: self._id).exists?
99
103
  end
@@ -37,7 +37,12 @@ module UnreadMongoid
37
37
  end
38
38
 
39
39
  def specifically_marked_ids(user)
40
- read_marks_query(user).ne(readable_id: nil).only(:readable_id).map(&:readable_id)
40
+ time_comparison = "this.timestamp >= this.readable_timestamp"
41
+
42
+ read_marks_query(user).ne(readable_id: nil)
43
+ .for_js(time_comparison)
44
+ .only(:readable_id)
45
+ .map(&:readable_id)
41
46
  end
42
47
  end
43
48
  end
@@ -1,3 +1,3 @@
1
1
  module UnreadMongoid
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/test/unread_test.rb CHANGED
@@ -157,7 +157,7 @@ class UnreadTest < ActiveSupport::TestCase
157
157
  end
158
158
 
159
159
  def test_cleanup_read_marks_not_delete_from_other_readables
160
- other_read_mark = @reader.read_marks.create! :readable_type => 'Foo', :readable_id => 42, :timestamp => 5.years.ago
160
+ other_read_mark = @reader.read_marks.create! :readable_type => 'Foo', :readable_id => 42, :timestamp => 5.years.ago, readable_timestamp: Time.now - 1.days
161
161
  Email.cleanup_read_marks!
162
162
  assert_equal true, ReadMark.where(_id: other_read_mark._id).exists?
163
163
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unread-mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hunter Haydel
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-31 00:00:00.000000000 Z
12
+ date: 2013-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid