class Tumblargh::Resource::Blog

Attributes

domain[RW]

Public Class Methods

new(domain, attrs=nil) click to toggle source
# File lib/tumblargh/resource/blog.rb, line 8
def initialize(domain, attrs=nil)
  @domain = domain
  self.attributes = attrs.nil? ? fetch : attrs
end

Public Instance Methods

attributes=(attrs) click to toggle source
Calls superclass method Tumblargh::Resource::Base#attributes=
# File lib/tumblargh/resource/blog.rb, line 13
def attributes=(attrs)
  attrs = attrs.with_indifferent_access

  # We passed in result from /posts, or a local file
  if attrs.include?(:posts) && attrs.include?(:blog)
    self.posts = attrs[:posts]
    attrs.delete(:posts)

    self.attributes = attrs[:blog]
  else
    super(attrs)
  end

  @attributes
end
fetch() click to toggle source
# File lib/tumblargh/resource/blog.rb, line 29
def fetch
  API.blog(domain)
end
fetch!() click to toggle source
# File lib/tumblargh/resource/blog.rb, line 33
def fetch!
  self.attributes = fetch
end
posts() click to toggle source
# File lib/tumblargh/resource/blog.rb, line 37
def posts
  @posts || self.posts = API.posts(domain)
  @posts # Whyyy??? Must I do this?
end
posts=(ary) click to toggle source
# File lib/tumblargh/resource/blog.rb, line 42
def posts=(ary)
  @posts = ary.map { |p| Post.new(p, self) }
end