No release in over 3 years
Low commit activity in last 3 years
Store settings in your relational database as a simple key value store. Can be used as a low performance cache if you want to store some things, and either want them reliably persisted past a cache server restart, or you just don't want a full cache.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.0
~> 1.0
~> 3.0
~> 0.9
>= 2.1.0
~> 13.0

Runtime

 Project Readme

Activerecord Settings

This gem creates a very simple activerecord based key value store. It can be useful if you want a place to store stuff that is more durable than a redis/memcache cache, or you simply don't want or need the complexity of running an additional cache.

Installation

Add this line to your application's Gemfile:

gem 'activerecord_settings'

And then execute:

$ bundle

Or install it yourself as:

$ gem install activerecord_settings

Usage

Create the migration to create the activerecord table with

bundle exec rails g activerecord_settings:install

Then you can set and get values like this

ActiverecordSettings::Setting.set('key', anything_yaml_can_serialize)
ActiverecordSettings::Setting.get('key')
=> anything_yaml_can_serialize

You can also set keys to have expiries

ActiverecordSettings::Setting.set('key', "It's morning", expires: 10.minutes.from_now)
ActiverecordSettings::Setting.get('key')
=> "It's morning"
# Some time passes, Thorin sings about gold
ActiverecordSettings::Setting.get('key')
=> nil

ActiverecordSettings::Setting is a bit of a mouthful, so you can create a shorthand for it by putting something like the following in an initiliazer

Setting = ActiverecordSettings::Setting

And then you can do this

Setting.set('key', anything_yaml_can_serialize)
Setting.get('key')
=> anything_yaml_can_serialize

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/dansingerman/activerecord_settings.

License

The gem is available as open source under the terms of the MIT License.