Class: Cheatly::Adapter::File

Inherits:
Object
  • Object
show all
Defined in:
lib/cheatly/adapter/file.rb

Instance Method Summary collapse

Instance Method Details

#allObject



11
12
13
# File 'lib/cheatly/adapter/file.rb', line 11

def all
  Dir["sheets/*.md"].map { |f| f.scan(/sheets\/(.*).md/)[0][0] }
end

#create(name, body) ⇒ Object



15
16
17
18
19
# File 'lib/cheatly/adapter/file.rb', line 15

def create(name, body)
  f = ::File.new("sheets/#{name}.md", "w")
  f.write(body)
  f.close
end

#find(name) ⇒ Object



6
7
8
9
# File 'lib/cheatly/adapter/file.rb', line 6

def find(name)
  path = "sheets/#{name}.md"
  ::File.read(path)
end

#update(name, body) ⇒ Object



21
22
23
24
# File 'lib/cheatly/adapter/file.rb', line 21

def update(name, body)
  ::File.delete("sheets/#{name}.md")
  create(name, body)
end