Class: Postview::Site

Inherits:
Object
  • Object
show all
Defined in:
lib/postview/site.rb

Overview

Copyright © 2009 Hallison Batista

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Site

Initialize site with attributes passed by arguments.



40
41
42
# File 'lib/postview/site.rb', line 40

def initialize(attributes = {})
  attributes.instance_variables_set_to(self)
end

Instance Attribute Details

#authorObject

Author site



13
14
15
# File 'lib/postview/site.rb', line 13

def author
  @author
end

#directoryObject

Remote directory for site



22
23
24
# File 'lib/postview/site.rb', line 22

def directory
  @directory
end

#domainObject

Domain for host site



19
20
21
# File 'lib/postview/site.rb', line 19

def domain
  @domain
end

#emailObject

Email to contact author



16
17
18
# File 'lib/postview/site.rb', line 16

def email
  @email
end

#findObject

Finder for posts



31
32
33
# File 'lib/postview/site.rb', line 31

def find
  @find
end

#find_in_archiveObject

Finder for archived posts



34
35
36
# File 'lib/postview/site.rb', line 34

def find_in_archive
  @find_in_archive
end

#find_in_draftsObject

Finder for drafted posts



37
38
39
# File 'lib/postview/site.rb', line 37

def find_in_drafts
  @find_in_drafts
end

#subtitleObject

Subtitle



10
11
12
# File 'lib/postview/site.rb', line 10

def subtitle
  @subtitle
end

#themeObject

Theme directory name.



25
26
27
# File 'lib/postview/site.rb', line 25

def theme
  @theme
end

#titleObject

Site title.



7
8
9
# File 'lib/postview/site.rb', line 7

def title
  @title
end

#tokenObject

Token pass.



28
29
30
# File 'lib/postview/site.rb', line 28

def token
  @token
end

Class Method Details

.tokenize(username, password, domain) ⇒ Object

Generate digest token.



71
72
73
74
# File 'lib/postview/site.rb', line 71

def self.tokenize(username, password, domain)
  require 'digest'
  Digest::SHA256.hexdigest("$#{username}?#{password}@#{domain}")
end

Instance Method Details

#authenticate?(username, password) ⇒ Boolean

Check authentication for user.

Returns:

  • (Boolean)


66
67
68
# File 'lib/postview/site.rb', line 66

def authenticate?(username, password)
  @token == self.class.tokenize(username, password, domain)
end

#find_all_posts_tagged_with(tag) ⇒ Object

Find all posts tagged with a specific tag.



55
56
57
# File 'lib/postview/site.rb', line 55

def find_all_posts_tagged_with(tag)
  [ find.all_posts_by_tag(tag), find_in_archive.all_posts_by_tag(tag) ]
end

#find_all_tagsObject

Find all tags from all posts and archived posts.



45
46
47
# File 'lib/postview/site.rb', line 45

def find_all_tags
  (find.all_tags + find_in_archive.all_tags).uniq.sort
end

#find_tag(tag) ⇒ Object

Find a specific tag from posts and archived posts.



50
51
52
# File 'lib/postview/site.rb', line 50

def find_tag(tag)
  find.tag(tag) || find_in_archive.tag(tag)
end

#search_posts(*values) ⇒ Object

Find posts using any string values. Returns two lists: posts and archived posts.



61
62
63
# File 'lib/postview/site.rb', line 61

def search_posts(*values)
  [ find.posts(*values), find_in_archive.posts(*values) ]
end