Class: Logbook::GistStore
- Inherits:
-
Object
- Object
- Logbook::GistStore
- Defined in:
- lib/gist_store/gist_store.rb
Constant Summary collapse
- DATE_FMT =
"%Y%m%d".freeze
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
Instance Method Summary collapse
- #all(id) ⇒ Object
- #create(covertext) ⇒ Object
- #destroy(id) ⇒ Object
- #get(id, time) ⇒ Object
-
#initialize ⇒ GistStore
constructor
A new instance of GistStore.
- #update(id, time, page) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ GistStore
Returns a new instance of GistStore.
8 9 10 11 |
# File 'lib/gist_store/gist_store.rb', line 8 def initialize @valid = !!(ENV['GITHUB_USER'] && ENV['GITHUB_PASSWORD']) @error = @valid ? '' : "Please set up GITHUB_USER and GITHUB_PASSWORD in your env." end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
6 7 8 |
# File 'lib/gist_store/gist_store.rb', line 6 def error @error end |
Instance Method Details
#all(id) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gist_store/gist_store.rb', line 34 def all(id) gist = Gist.read_raw(id) return nil unless gist entries = gist['files'].reject{|k| ["cover"].include? k }.map do |fname, v| { :date => DateTime.strptime(v['filename'], DATE_FMT), :content => v['content'] } end { :id => id, :cover => gist['files']['cover']['content'], :entries => entries } end |
#create(covertext) ⇒ Object
25 26 27 28 |
# File 'lib/gist_store/gist_store.rb', line 25 def create(covertext) u = URI.parse Gist.write(gist_data(covertext, "cover"), true) u.path[1..-1] end |
#destroy(id) ⇒ Object
48 49 50 |
# File 'lib/gist_store/gist_store.rb', line 48 def destroy(id) Gist.delete(id) end |
#get(id, time) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/gist_store/gist_store.rb', line 17 def get(id, time) gist = Gist.read_raw(id) return nil unless gist file = gist['files'][gist_file(time)] return nil unless file file['content'] end |
#update(id, time, page) ⇒ Object
30 31 32 |
# File 'lib/gist_store/gist_store.rb', line 30 def update(id, time, page) Gist.update(id, gist_data(page, gist_file(time))) end |
#valid? ⇒ Boolean
13 14 15 |
# File 'lib/gist_store/gist_store.rb', line 13 def valid? @valid end |