Sha256: a61101ed4bdeb3ddb57a05905a78b099f08202085e780c2a6e82b151ae63ca82

Contents?: true

Size: 916 Bytes

Versions: 2

Compression:

Stored size: 916 Bytes

Contents

class Store
  class << self

    attr_writer :app_root

    def set(store_classname, app_root)
      # @store_class is literally the class FileStore by default, or if a class name is passed in, another subclass of Store
      @store_class = store_classname ? Kernel.const_get(store_classname) : FileStore
      @store_class.app_root = app_root
      @store_class
    end

    def method_missing(*args)
      # For any method not implemented in *this* class, pass the method call through to the designated Store subclass
      @store_class.send(*args)
    end

    ### GET

    def get_hash(path)
      json = get_text path
      JSON.parse json if json
    end

    alias_method :get_page, :get_hash

    ### PUT

    def put_hash(path, ruby_data, metadata={})
      json = JSON.pretty_generate(ruby_data)
      put_text path, json, metadata
      ruby_data
    end

    alias_method :put_page, :put_hash

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

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