Class: Cheatly::Sheet
- Inherits:
-
Object
- Object
- Cheatly::Sheet
- Defined in:
- lib/cheatly/sheet.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#persisted ⇒ Object
Returns the value of attribute persisted.
-
#title ⇒ Object
Returns the value of attribute title.
Class Method Summary collapse
Instance Method Summary collapse
- #create ⇒ Object
-
#initialize(title, body = nil, options = {}) ⇒ Sheet
constructor
A new instance of Sheet.
- #save ⇒ Object
- #to_s ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(title, body = nil, options = {}) ⇒ Sheet
Returns a new instance of Sheet.
5 6 7 8 |
# File 'lib/cheatly/sheet.rb', line 5 def initialize(title, body = nil, = {}) @title, @body = title, body @persisted = [:persisted] || false end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
3 4 5 |
# File 'lib/cheatly/sheet.rb', line 3 def body @body end |
#persisted ⇒ Object
Returns the value of attribute persisted.
3 4 5 |
# File 'lib/cheatly/sheet.rb', line 3 def persisted @persisted end |
#title ⇒ Object
Returns the value of attribute title.
3 4 5 |
# File 'lib/cheatly/sheet.rb', line 3 def title @title end |
Class Method Details
.adapter ⇒ Object
46 47 48 |
# File 'lib/cheatly/sheet.rb', line 46 def self.adapter @adapter ||= Cheatly::Adapter::GitHub.new end |
.all ⇒ Object
41 42 43 44 |
# File 'lib/cheatly/sheet.rb', line 41 def self.all handles = adapter.all handles.map { |h| Sheet.new(h, nil) } end |
.find(name) ⇒ Object
31 32 33 34 35 36 37 38 39 |
# 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. nil end |
Instance Method Details
#create ⇒ Object
14 15 16 17 |
# File 'lib/cheatly/sheet.rb', line 14 def create adapter.create(title, body) @persisted = true end |
#save ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/cheatly/sheet.rb', line 23 def save if @persisted update else create end end |
#to_s ⇒ Object
10 11 12 |
# File 'lib/cheatly/sheet.rb', line 10 def to_s body.to_s end |
#update ⇒ Object
19 20 21 |
# File 'lib/cheatly/sheet.rb', line 19 def update adapter.update(title, body) end |