Coder Social home page Coder Social logo

joshuasiler / entity_storage Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 1.0 222 KB

An easy to use persistent Key/Value store for any Rails project. Designed to store config values and application wide state that needs to survive server restarts.

Home Page: http://eatenbyagrue.github.com/entity_storage/

Ruby 100.00%

entity_storage's Introduction

entity_storage

github.com/joshuasiler/entity_storage

DESCRIPTION:

An easy to use Key/Value store for any Ruby on Rails project. Like Memcache, only persistent. Stores config values and application wide state in the database in order to survive server restarts.

Designed to allow you to add persistent value storage to any Rails project in about 5 minutes.

Additionally, allows users to set a list of default keys that auto-initializes baseline key/value pairs in the database for easy initialization.

SYNOPSIS:

You can use the entity store like so:

# Get key value.
e = EntityStore["testkey"]
e = EntityStore.testkey
e = EntityStore[:testkey]

# sets key named 'happened' to a Time object of now
EntityStore[:happened] = Time.now
EntityStore["happened"] = Time.now
EntityStore.happened = Time.now

# find out it's default, even if it's been changed
e = EntityStore.default(:testkey)

# or
e = EntityStore.defaults[:testkey]

# set it back to default
EntityStore.default!(:testkey)

# delete an item
EntityStore.delete(key)

All EntityStorage operations sync immediately with the database, so a server shutdown will not impact stored values.

If you access a key that doesn’t exist, and is specified in default list, will be initialized and returned. If not in default list, will return nil.

Keys can be up to 250 characters in length. Values can be practically any size, and consist of any object. Objects are marshalled back and forth between database.

REQUIREMENTS:

As of 2.1.5, key length reduced to allow indexing on MySQL 5.6

As of 2.1.4, tested with Ruby 2.1.2.

As of 2.1.0, the MySQL2 gem and Ruby 1.9.3 are now supported.

As of 2.0.0, Rails 3.0.3 gems or above required.

Version up to 1.0.4 requires Ruby 1.8.7 and ActiveRecord 2.2.3 or above (probably works with earlier versions, but has not been tested.) (earlier versions had an incorrect gem name, and are installed with ‘gem install entity_storage’)

INSTALL:

Install the gem(s):

sudo gem install entity_storage

Or download the source above and run, customized for version and environment:

sudo gem install PATH/entity_storage.#.#.#.gem

Put the following in an initializer file named RAILS_ROOT/config/initializers/entity_storage.rb

require 'entity_storage'
DEFAULT_KEYS = { "testkey" => DateTime.parse("1-1-900"), "also test" => 2, "long ass key that I probably wouldn't use" => false }
EntityStore = EntityStorage::Storage.new(DEFAULT_KEYS)

On initialization, if the table “entity_storage” doesn’t exist, it will be created. If you already have a table with that name, it must be in the correct format (previously created by this gem.)

You can pass a hash full of default key/value pairs. If the application accesses one of the keys, and it doesn’t already exist, it will initiliaze that key with the default value. Good for getting your app to an initial starting state.

LICENSE:

(The MIT License)

Copyright © 2009-2015 Joshua Siler

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

entity_storage's People

Contributors

joshuasiler avatar

Stargazers

Liang avatar  avatar  avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

gdomingu

entity_storage's Issues

Only supports MySQL

Currently the table existence check only supports MySQL. Needs to be updated to support SQL lite and other databases. Specifically, the EntityStorage::Storage initializer needs to use something other than mysql specific "show tables" command to detect existence of a table.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.