Class: ReaderPage
- Inherits:
-
Page
- Object
- Page
- ReaderPage
- Includes:
- WillPaginate::ViewHelpers
- Defined in:
- app/models/reader_page.rb
Instance Attribute Summary collapse
-
#group ⇒ Object
Returns the value of attribute group.
-
#reader ⇒ Object
Returns the value of attribute reader.
Instance Method Summary collapse
- #cache? ⇒ Boolean
- #current_reader ⇒ Object
- #find_by_url(url, live = true, clean = false) ⇒ Object
- #groups ⇒ Object
- #public? ⇒ Boolean
- #readers ⇒ Object
- #url_for(thing) ⇒ Object
- #visible? ⇒ Boolean
Instance Attribute Details
#group ⇒ Object
Returns the value of attribute group.
3 4 5 |
# File 'app/models/reader_page.rb', line 3 def group @group end |
#reader ⇒ Object
Returns the value of attribute reader.
3 4 5 |
# File 'app/models/reader_page.rb', line 3 def reader @reader end |
Instance Method Details
#cache? ⇒ Boolean
23 24 25 |
# File 'app/models/reader_page.rb', line 23 def cache? public? end |
#current_reader ⇒ Object
7 8 9 |
# File 'app/models/reader_page.rb', line 7 def current_reader Reader.current end |
#find_by_url(url, live = true, clean = false) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/reader_page.rb', line 43 def find_by_url(url, live = true, clean = false) url = clean_url(url) if clean my_url = self.url return false unless url =~ /^#{Regexp.quote(my_url)}(.*)/ raise ReaderError::AccessDenied unless visible? params = $1.split('/').compact self.group = Group.find_by_slug(params.first) if params.first =~ /\w/ self.reader = Reader.find_by_id(params.last) if params.last !~ /\D/ raise ReaderError::AccessDenied, "Group visibility denied" if group && !group.visible_to?(current_reader) raise ReaderError::AccessDenied, "Reader visibility denied: #{current_reader} (#{current_reader.preferred_name}) cannot see #{reader} (#{reader.preferred_name})" if reader && !reader.visible_to?(current_reader) raise ActiveRecord::RecordNotFound if reader && group && !reader.has_group?(group) self end |
#groups ⇒ Object
19 20 21 |
# File 'app/models/reader_page.rb', line 19 def groups Group.visible_to(current_reader) end |
#public? ⇒ Boolean
27 28 29 |
# File 'app/models/reader_page.rb', line 27 def public? Radiant.config['reader.directory_visibility'] == 'public' end |
#readers ⇒ Object
11 12 13 14 15 16 17 |
# File 'app/models/reader_page.rb', line 11 def readers if group group.readers.visible_to(current_reader) else Reader.visible_to(current_reader) end end |
#url_for(thing) ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/models/reader_page.rb', line 35 def url_for(thing) if thing.is_a?(Reader) File.join(self.url, thing.id) elsif thing.is_a?(Group) File.join(self.url, thing.slug) end end |
#visible? ⇒ Boolean
31 32 33 |
# File 'app/models/reader_page.rb', line 31 def visible? public? || current_reader end |