Sha256: 1caf9cce01690a250d9fdf0f5c03c2a09529ec11183da281f9ddb0b1a7986690

Contents?: true

Size: 1.04 KB

Versions: 2

Compression:

Stored size: 1.04 KB

Contents

class FileStore < Store
  class << self

    ### GET

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

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

    ### PUT

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

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

    ### COLLECTIONS

    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

    ### UTILITY

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

    def mkdir(directory)
      FileUtils.mkdir_p directory
    end

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wiki-0.1.0 lib/wiki/stores/file.rb
wiki-0.0.1 lib/wiki/stores/file.rb