module ActiveGist::ClassMethods

Public Instance Methods

all(type = :all) click to toggle source
# File lib/active_gist/class_methods.rb, line 32
def all(type = :all)
  case type
    when :all then JSON.parse api.get(:accept => 'application/json')
    when :public then JSON.parse api['public'].get(:accept => 'application/json')
    when :starred then JSON.parse api['starred'].get(:accept => 'application/json')
    else raise ArgumentError, "Unknown type: #{type.inspect} (expected one of [:all, :public, :starred])"
  end.collect do |hash|
    load hash
  end
end
count(type = :all) click to toggle source
# File lib/active_gist/class_methods.rb, line 18
def count(type = :all)
  all(type).count
end
create(options = {}) click to toggle source
# File lib/active_gist/class_methods.rb, line 6
def create(options = {})
  new(options).tap { |gist| gist.save }
end
create!(options = {}) click to toggle source
# File lib/active_gist/class_methods.rb, line 2
def create!(options = {})
  new(options).tap { |gist| gist.save! }
end
find(id) click to toggle source
# File lib/active_gist/class_methods.rb, line 22
def find(id)
  load JSON.parse(api[id].get(:accept => 'application/json'))
end
first(type = :all) click to toggle source
# File lib/active_gist/class_methods.rb, line 10
def first(type = :all)
  all(type).first
end
last(type = :all) click to toggle source
# File lib/active_gist/class_methods.rb, line 14
def last(type = :all)
  all(type).last
end
load(hash) click to toggle source
# File lib/active_gist/class_methods.rb, line 26
def load(hash)
  new(hash).tap do |instance|
    instance.changed_attributes.clear
  end
end