Class: FileStore

Inherits:
Store show all
Defined in:
lib/wiki/stores/file.rb

Class Method Summary collapse

Methods inherited from Store

get_hash, method_missing, put_hash, set

Class Method Details

.annotated_pages(pages_dir) ⇒ Object

COLLECTIONS



29
30
31
32
33
34
35
36
37
# File 'lib/wiki/stores/file.rb', line 29

def annotated_pages(pages_dir)
  Dir.foreach(pages_dir).reject{|name|name =~ /^\./}.collect do |name|
    page = get_page(File.join pages_dir, name)
    page.merge!({
      'name' => name,
      'updated_at' => File.new("#{pages_dir}/#{name}").mtime
    })
  end
end

.exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/wiki/stores/file.rb', line 49

def exists?(path)
  File.exists?(path)
end

.farm?(data_root) ⇒ Boolean

UTILITY

Returns:

  • (Boolean)


41
42
43
# File 'lib/wiki/stores/file.rb', line 41

def farm?(data_root)
  ENV['FARM_MODE'] || File.exists?(File.join data_root, "farm")
end

.get_blob(path) ⇒ Object



10
11
12
# File 'lib/wiki/stores/file.rb', line 10

def get_blob(path)
  File.binread path if File.exist? path
end

.get_text(path) ⇒ Object

GET



6
7
8
# File 'lib/wiki/stores/file.rb', line 6

def get_text(path)
  File.read path if File.exist? path
end

.mkdir(directory) ⇒ Object



45
46
47
# File 'lib/wiki/stores/file.rb', line 45

def mkdir(directory)
  FileUtils.mkdir_p directory
end

.put_blob(path, blob) ⇒ Object



22
23
24
25
# File 'lib/wiki/stores/file.rb', line 22

def put_blob(path, blob)
  File.open(path, 'wb'){ |file| file.write blob }
  blob
end

.put_text(path, text, metadata = nil) ⇒ Object

PUT



16
17
18
19
20
# File 'lib/wiki/stores/file.rb', line 16

def put_text(path, text, =nil)
  # Note: metadata is ignored for filesystem storage
  File.open(path, 'w'){ |file| file.write text }
  text
end