Class: ReaderPage

Inherits:
Page
  • Object
show all
Includes:
WillPaginate::ViewHelpers
Defined in:
app/models/reader_page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#groupObject

Returns the value of attribute group.



3
4
5
# File 'app/models/reader_page.rb', line 3

def group
  @group
end

#readerObject

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

Returns:

  • (Boolean)


23
24
25
# File 'app/models/reader_page.rb', line 23

def cache?
  public?
end

#current_readerObject



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

Raises:

  • (ReaderError::AccessDenied)


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

#groupsObject



19
20
21
# File 'app/models/reader_page.rb', line 19

def groups
  Group.visible_to(current_reader)
end

#public?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'app/models/reader_page.rb', line 27

def public?
  Radiant.config['reader.directory_visibility'] == 'public'
end

#readersObject



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

Returns:

  • (Boolean)


31
32
33
# File 'app/models/reader_page.rb', line 31

def visible?
  public? || current_reader
end