Class: Wonki::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/wonki/storage.rb

Instance Method Summary collapse

Constructor Details

#initialize(repo_path) ⇒ Storage

Returns a new instance of Storage.



6
7
8
9
# File 'lib/wonki/storage.rb', line 6

def initialize(repo_path)
  @repo_path = repo_path
  @repository = Grit::Repo.new(@repo_path)
end

Instance Method Details

#build(route) ⇒ Object



11
12
13
14
15
16
# File 'lib/wonki/storage.rb', line 11

def build(route)
  route_name = route[1..-1] # strip leading slash
  data = find(route_name)
  mod_date = get_mod_date(route_name)
  {:content => data, :last_modified => mod_date, :route_name => route_name}
end

#find(name) ⇒ Object



18
19
20
21
22
# File 'lib/wonki/storage.rb', line 18

def find(name)
  blob = (@repository.tree/name)
  raise Wonki::PageNotFound.new if blob.nil?
  blob.data
end

#get_mod_date(name) ⇒ Object



24
25
26
# File 'lib/wonki/storage.rb', line 24

def get_mod_date(name)
  @repository.commits.first.committed_date  # date of the last commit to the repo.
end