class Cheatly::Sheet

Attributes

body[RW]
persisted[RW]
title[RW]

Public Class Methods

adapter() click to toggle source
# File lib/cheatly/sheet.rb, line 46
def self.adapter
  @adapter ||= Cheatly::Adapter::GitHub.new
end
all() click to toggle source
# File lib/cheatly/sheet.rb, line 41
def self.all
  handles = adapter.all
  handles.map { |h| Sheet.new(h, nil) }
end
find(name) click to toggle source
# File lib/cheatly/sheet.rb, line 31
def self.find(name)
  body = adapter.find(name)
  self.new(name, body, persisted: true)
rescue Octokit::NotFound
  nil
rescue Exception => e
  puts e.message
  nil
end
new(title, body = nil, options = {}) click to toggle source
# File lib/cheatly/sheet.rb, line 5
def initialize(title, body = nil, options = {})
  @title, @body = title, body
  @persisted = options[:persisted] || false
end

Public Instance Methods

create() click to toggle source
# File lib/cheatly/sheet.rb, line 14
def create
  adapter.create(title, body)
  @persisted = true
end
save() click to toggle source
# File lib/cheatly/sheet.rb, line 23
def save
  if @persisted
    update
  else
    create
  end
end
to_s() click to toggle source
# File lib/cheatly/sheet.rb, line 10
def to_s
  body.to_s
end
update() click to toggle source
# File lib/cheatly/sheet.rb, line 19
def update
  adapter.update(title, body)
end

Private Instance Methods

adapter() click to toggle source
# File lib/cheatly/sheet.rb, line 52
def adapter
  self.class.adapter
end