Sha256: 0a9b5263ba8e63f8410bd8e0f0847c3fa6310951f6c90aa97123e7398ed16635

Contents?: true

Size: 1.88 KB

Versions: 27

Compression:

Stored size: 1.88 KB

Contents

require 'util/mongo_persisted_collection'
require 'util/json_file_persisted_collection'
require 'util/mongo_persisted_hash'
require 'util/json_file_persisted_hash'
require 'fileutils'


module Nutella

  module App

    # Implements basic app-dependent persistence for app-level components
    module Persist

      # This method returns a MongoDB-backed store (i.e. persistence)
      # for a collection (i.e. an Array)
      # @param [String] name the name of the store
      # @return [MongoPersistedCollection] a MongoDB-backed collection store
      def self.get_mongo_collection_store( name )
        MongoPersistedCollection.new Nutella.mongo_host, Nutella.app_id, name
      end

      # This method returns a MongoDB-backed store (i.e. persistence)
      # for a single object (i.e. an Hash)
      # @param [String] name the name of the store
      # @return [MongoPersistedHash] a MongoDB-backed Hash store
      def self.get_mongo_object_store( name )
        MongoPersistedHash.new Nutella.mongo_host, Nutella.app_id, 'app_persisted_hashes', name
      end

      # This method returns a JSON-file-backed store (i.e. persistence)
      # for a collection (i.e. an Array)
      # @param [String] name the name of the store
      # @return [JSONFilePersistedCollection] a JSON-file-backed collection store
      def self.get_json_collection_store( name )
        file_path = "data/#{name}.json"
        FileUtils.mkdir_p 'data/'
        JSONFilePersistedCollection.new file_path
      end

      # This method returns a JSON-file-backed store (i.e. persistence)
      # for a single object (i.e. an Hash)
      # @param [String] name the name of the store
      # @return [JSONFilePersistedHash] a JSON-file-backed Hash store
      def self.get_json_object_store( name )
        file_path = "data/#{name}.json"
        FileUtils.mkdir_p 'data/'
        JSONFilePersistedHash.new file_path
      end
    end
  end

end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
nutella_lib-0.6.0 lib/nutella_lib/app_persist.rb
nutella_lib-0.5.0 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.27 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.26 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.25 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.24 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.23 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.22 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.21 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.20 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.19 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.18 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.17 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.16 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.15 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.14 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.13 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.12 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.11 lib/nutella_lib/app_persist.rb
nutella_lib-0.4.10 lib/nutella_lib/app_persist.rb