Class: Tumblr::Blog

Inherits:
Object show all
Extended by:
Query::DelegateMethods
Defined in:
lib/tumblr/blog.rb

Constant Summary collapse

STORAGE_KEY =
"gorgon:blog:entries"

Class Attribute Summary collapse

Class Method Summary collapse

Methods inherited from Object

array_attribute, #as_json, attributes, boolean_attribute, build, #commit, date_attribute, #dom_class, #etag, numeric_attribute, object_attribute, objectify, #serialize, #storage, string_attribute, systematize, #to_json, unserialize

Class Attribute Details

.page_sizeObject

Returns the value of attribute page_size.



12
13
14
# File 'lib/tumblr/blog.rb', line 12

def page_size
  @page_size
end

Class Method Details

.clear!Object



18
19
20
21
# File 'lib/tumblr/blog.rb', line 18

def clear!
  Tumblr.config.redis.keys("#{STORAGE_KEY}:*").each { |key| Tumblr.config.redis.del(key) }
  index.clear
end

.entries(slugs = nil) ⇒ Object



44
45
46
47
48
49
# File 'lib/tumblr/blog.rb', line 44

def entries(slugs=nil)
  slugs ||= index
  entries = slugs.collect { |slug| entry(slug) }
  entries.compact!
  entries
end

.entry(slug) ⇒ Object



55
56
57
58
# File 'lib/tumblr/blog.rb', line 55

def entry(slug)
  value = Redis::Value.new("#{STORAGE_KEY}:#{slug}", Tumblr.config.redis)
  Tumblr::Object.unserialize(value.value)
end

.find(slug) ⇒ Object



60
61
62
# File 'lib/tumblr/blog.rb', line 60

def find(slug)
  entry(slug)
end

.indexObject



51
52
53
# File 'lib/tumblr/blog.rb', line 51

def index
  @index ||= Redis::List.new(STORAGE_KEY, Tumblr.config.redis)
end

.page(n) ⇒ Object



68
69
70
# File 'lib/tumblr/blog.rb', line 68

def page(n)
  query.page([1, n.to_i].max)
end

.refresh!(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/tumblr/blog.rb', line 23

def refresh!(options={})
  clear!

  page = options[:min] || 1
  per_page = options[:per_page] || 100
  max_page = options[:max]

  loop do
    posts = Post.per_page(per_page).page(page)
    if posts.length > 0
      page = posts.next_page
      posts.each do |post|
        index << post.slug
        post.commit
      end
      break if page.nil? || (max_page && page > max_page)
    end
  end
  true
end

.tagged_with(tag) ⇒ Object



72
73
74
# File 'lib/tumblr/blog.rb', line 72

def tagged_with(tag)
  query.tagged_with(tag)
end

.tagsObject



64
65
66
# File 'lib/tumblr/blog.rb', line 64

def tags
  Redis::Set.new("#{STORAGE_KEY}:tags", Tumblr.config.redis)
end