Module: ReadActivity::Reader::InstanceMethods
- Defined in:
- lib/read_activity/reader.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *arguments, &block) ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/read_activity/reader.rb', line 61
def method_missing(method, *arguments, &block)
if method.to_s =~ /^read_(.*)/
readables_marked_as_read($1.singularize.camelize.constantize, *arguments, &block)
elsif method.to_s =~ /^unread_(.*)/
readables_unmarked_as_read($1.singularize.camelize.constantize, *arguments, &block)
else
super
end
end
|
Instance Method Details
#read!(readable) ⇒ Object
inverse of Readable#read_by!
26
27
28
|
# File 'lib/read_activity/reader.rb', line 26
def read!(readable)
readable.read_by!(self)
end
|
#read?(readable) ⇒ Boolean
inverse of Readable#read_by?
31
32
33
|
# File 'lib/read_activity/reader.rb', line 31
def read?(readable)
readable.read_by?(self)
end
|
#read_at(readable = nil) ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/read_activity/reader.rb', line 43
def read_at(readable = nil)
read_at = nil
if self.read_activity_marks.loaded?
read_at = self.read_activity_marks.first.try(:created_at)
end
if read_at.nil? && readable
if readable.read_activity_marks.loaded?
read_at = readable.read_activity_marks.first.try(:created_at)
else
read_at = self.read_activity_marks.where(readable: readable).first.try(:created_at)
end
end
return read_at
end
|
#readables_marked_as_read(klass) ⇒ Object
35
36
37
|
# File 'lib/read_activity/reader.rb', line 35
def readables_marked_as_read(klass)
klass.send(:find_read_by, self)
end
|
#readables_unmarked_as_read(klass) ⇒ Object
39
40
41
|
# File 'lib/read_activity/reader.rb', line 39
def readables_unmarked_as_read(klass)
klass.send(:find_unread_by, self)
end
|
#respond_to_missing?(method, include_private = false) ⇒ Boolean
71
72
73
74
75
76
77
78
|
# File 'lib/read_activity/reader.rb', line 71
def respond_to_missing?(method, include_private = false)
method_name = method.to_s
if method_name.start_with?("read_") or method_name.start_with?("unread_")
true
else
super
end
end
|