unread 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.
- data/.travis.yml +1 -0
- data/README.md +3 -3
- data/changelog.md +6 -0
- data/ci/Gemfile.rails-2.3.x +1 -1
- data/ci/Gemfile.rails-3.0.x +1 -1
- data/ci/Gemfile.rails-3.1.x +7 -0
- data/lib/unread/acts_as_readable.rb +20 -14
- data/lib/unread/version.rb +1 -1
- data/test/test_helper.rb +5 -7
- data/test/unread_test.rb +9 -1
- data/unread.gemspec +7 -1
- metadata +11 -10
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -3,7 +3,7 @@ Unread
|
|
3
3
|
|
4
4
|
Gem to manage read/unread status of ActiveRecord objects - and it's fast.
|
5
5
|
|
6
|
-
[](http://travis-ci.org/ledermann/unread)
|
7
7
|
|
8
8
|
## Features
|
9
9
|
|
@@ -17,8 +17,8 @@ Gem to manage read/unread status of ActiveRecord objects - and it's fast.
|
|
17
17
|
|
18
18
|
## Requirements
|
19
19
|
|
20
|
-
* Ruby 1.8.7
|
21
|
-
* ActiveRecord
|
20
|
+
* Ruby 1.8.7 or 1.9.2
|
21
|
+
* ActiveRecord 2.3.x, 3.0.x, 3.1.x (tested with SQLite and MySQL)
|
22
22
|
* Needs a timestamp field in your models (e.g. created_at) with a database index on it
|
23
23
|
|
24
24
|
|
data/changelog.md
CHANGED
data/ci/Gemfile.rails-2.3.x
CHANGED
data/ci/Gemfile.rails-3.0.x
CHANGED
@@ -5,6 +5,9 @@ module Unread
|
|
5
5
|
|
6
6
|
module ActsAsReadable
|
7
7
|
def acts_as_reader
|
8
|
+
# Ignore multiple calls
|
9
|
+
return if ReadMark.reader_class
|
10
|
+
|
8
11
|
ReadMark.reader_class = self
|
9
12
|
|
10
13
|
has_many :read_marks, :dependent => :delete_all
|
@@ -17,6 +20,9 @@ module Unread
|
|
17
20
|
end
|
18
21
|
|
19
22
|
def acts_as_readable(options={})
|
23
|
+
# Ignore multiple calls
|
24
|
+
return if self.included_modules.include?(InstanceMethods)
|
25
|
+
|
20
26
|
options.reverse_merge!({ :on => :updated_at })
|
21
27
|
if respond_to?(:class_attribute)
|
22
28
|
class_attribute :readable_options
|
@@ -34,8 +40,7 @@ module Unread
|
|
34
40
|
scope_method = ActiveRecord::VERSION::MAJOR < 3 ? :named_scope : :scope
|
35
41
|
|
36
42
|
send scope_method, :unread_by, lambda { |user|
|
37
|
-
|
38
|
-
raise ArgumentError unless user.is_a?(ReadMark.reader_class)
|
43
|
+
assert_reader(user)
|
39
44
|
|
40
45
|
result = { :joins => "LEFT JOIN read_marks ON read_marks.readable_type = '#{self.base_class.name}'
|
41
46
|
AND read_marks.readable_id = #{self.table_name}.id
|
@@ -55,11 +60,10 @@ module Unread
|
|
55
60
|
|
56
61
|
module ClassMethods
|
57
62
|
def mark_as_read!(target, options)
|
58
|
-
check_reader
|
59
63
|
raise ArgumentError unless target == :all || target.is_a?(Array)
|
60
64
|
|
61
65
|
user = options[:for]
|
62
|
-
|
66
|
+
assert_reader(user)
|
63
67
|
|
64
68
|
if target == :all
|
65
69
|
reset_read_marks!(user)
|
@@ -80,9 +84,7 @@ module Unread
|
|
80
84
|
end
|
81
85
|
|
82
86
|
def read_mark(user)
|
83
|
-
|
84
|
-
raise ArgumentError unless user.is_a?(ReadMark.reader_class)
|
85
|
-
|
87
|
+
assert_reader(user)
|
86
88
|
user.read_marks.readable_type(self.base_class.name).global.first
|
87
89
|
end
|
88
90
|
|
@@ -110,7 +112,7 @@ module Unread
|
|
110
112
|
end
|
111
113
|
|
112
114
|
def cleanup_read_marks!
|
113
|
-
|
115
|
+
assert_reader
|
114
116
|
|
115
117
|
ReadMark.reader_class.find_each do |user|
|
116
118
|
ReadMark.transaction do
|
@@ -130,7 +132,7 @@ module Unread
|
|
130
132
|
end
|
131
133
|
|
132
134
|
def reset_read_marks!(user = :all)
|
133
|
-
|
135
|
+
assert_reader
|
134
136
|
|
135
137
|
ReadMark.transaction do
|
136
138
|
if user == :all
|
@@ -149,8 +151,14 @@ module Unread
|
|
149
151
|
true
|
150
152
|
end
|
151
153
|
|
152
|
-
def
|
153
|
-
|
154
|
+
def assert_reader(user=nil)
|
155
|
+
if ReadMark.reader_class
|
156
|
+
if user && !user.is_a?(ReadMark.reader_class)
|
157
|
+
raise ArgumentError, "Class #{user.class.name} is not registered by acts_as_reader!"
|
158
|
+
end
|
159
|
+
else
|
160
|
+
raise RuntimeError, 'There is no class using acts_as_reader!'
|
161
|
+
end
|
154
162
|
end
|
155
163
|
end
|
156
164
|
|
@@ -160,10 +168,8 @@ module Unread
|
|
160
168
|
end
|
161
169
|
|
162
170
|
def mark_as_read!(options)
|
163
|
-
self.class.check_reader
|
164
|
-
|
165
171
|
user = options[:for]
|
166
|
-
|
172
|
+
self.class.assert_reader(user)
|
167
173
|
|
168
174
|
ReadMark.transaction do
|
169
175
|
if unread?(user)
|
data/lib/unread/version.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -1,17 +1,13 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
|
3
|
-
gem 'activerecord'
|
4
|
-
gem 'mocha'
|
5
|
-
|
6
3
|
require 'test/unit'
|
7
|
-
require 'active_record'
|
8
4
|
require 'active_support'
|
9
5
|
require 'active_support/test_case'
|
6
|
+
require 'active_record'
|
10
7
|
|
11
8
|
require File.dirname(__FILE__) + '/../init.rb'
|
12
9
|
|
13
|
-
|
14
|
-
configs = YAML.load_file('test/database.yml')
|
10
|
+
configs = YAML.load_file(File.dirname(__FILE__) + '/database.yml')
|
15
11
|
ActiveRecord::Base.configurations = configs
|
16
12
|
|
17
13
|
db_name = ENV['DB'] || 'sqlite'
|
@@ -25,4 +21,6 @@ end
|
|
25
21
|
|
26
22
|
class Email < ActiveRecord::Base
|
27
23
|
acts_as_readable :on => :updated_at
|
28
|
-
end
|
24
|
+
end
|
25
|
+
|
26
|
+
puts "Testing with ActiveRecord #{ActiveRecord::VERSION::STRING}"
|
data/test/unread_test.rb
CHANGED
@@ -26,6 +26,10 @@ class UnreadTest < ActiveSupport::TestCase
|
|
26
26
|
|
27
27
|
assert_equal 2, Email.unread_by(@user).count
|
28
28
|
assert_equal 2, Email.unread_by(@other_user).count
|
29
|
+
|
30
|
+
assert_raise(ArgumentError) {
|
31
|
+
Email.unread_by(42)
|
32
|
+
}
|
29
33
|
end
|
30
34
|
|
31
35
|
def test_scope_after_reset
|
@@ -35,9 +39,13 @@ class UnreadTest < ActiveSupport::TestCase
|
|
35
39
|
assert_equal 1, Email.unread_by(@user).count
|
36
40
|
end
|
37
41
|
|
38
|
-
def
|
42
|
+
def test_unread_after_create
|
39
43
|
assert_equal true, @email1.unread?(@user)
|
40
44
|
assert_equal true, @email1.unread?(@other_user)
|
45
|
+
|
46
|
+
assert_raise(ArgumentError) {
|
47
|
+
@email1.unread?(42)
|
48
|
+
}
|
41
49
|
end
|
42
50
|
|
43
51
|
def test_unread_after_update
|
data/unread.gemspec
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
3
|
require "unread/version"
|
4
|
+
require 'active_record/version'
|
4
5
|
|
5
6
|
Gem::Specification.new do |s|
|
6
7
|
s.name = "unread"
|
@@ -23,5 +24,10 @@ Gem::Specification.new do |s|
|
|
23
24
|
s.add_development_dependency 'rake'
|
24
25
|
s.add_development_dependency 'mocha'
|
25
26
|
s.add_development_dependency 'sqlite3'
|
26
|
-
|
27
|
+
|
28
|
+
if ActiveRecord::VERSION::MAJOR == 3 && ActiveRecord::VERSION::MINOR >= 1
|
29
|
+
s.add_development_dependency 'mysql2', '>= 0.3.6'
|
30
|
+
else
|
31
|
+
s.add_development_dependency 'mysql2', '~> 0.2.11'
|
32
|
+
end
|
27
33
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unread
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Georg Ledermann
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-08-
|
18
|
+
date: 2011-08-31 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: activerecord
|
@@ -80,14 +80,14 @@ dependencies:
|
|
80
80
|
requirement: &id005 !ruby/object:Gem::Requirement
|
81
81
|
none: false
|
82
82
|
requirements:
|
83
|
-
- -
|
83
|
+
- - ">="
|
84
84
|
- !ruby/object:Gem::Version
|
85
|
-
hash:
|
85
|
+
hash: 31
|
86
86
|
segments:
|
87
87
|
- 0
|
88
|
-
-
|
89
|
-
-
|
90
|
-
version: 0.
|
88
|
+
- 3
|
89
|
+
- 6
|
90
|
+
version: 0.3.6
|
91
91
|
type: :development
|
92
92
|
version_requirements: *id005
|
93
93
|
description: "This gem creates a scope for unread objects and adds methods to mark objects as read "
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- changelog.md
|
110
110
|
- ci/Gemfile.rails-2.3.x
|
111
111
|
- ci/Gemfile.rails-3.0.x
|
112
|
+
- ci/Gemfile.rails-3.1.x
|
112
113
|
- init.rb
|
113
114
|
- lib/app/models/read_mark.rb
|
114
115
|
- lib/unread.rb
|
@@ -149,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
150
|
requirements: []
|
150
151
|
|
151
152
|
rubyforge_project: unread
|
152
|
-
rubygems_version: 1.8.
|
153
|
+
rubygems_version: 1.8.10
|
153
154
|
signing_key:
|
154
155
|
specification_version: 3
|
155
156
|
summary: Manages read/unread status of ActiveRecord objects
|