static_record

In some cases creating database table for storing immutable records just so you can join data is an overkill. By immutable records think hard-coded categories, 3rd party API error codes, ... in general data that is controlled by developers rather than users. With such data you are much better of not using database for it - imaging creating migration for every update on i.e.. category description. Creating GUI for it is certainly an option if you don't mind throwing more code into the project for this trivial task.

StaticRecord provides you with the preloading schema-free objects from Yaml to OpenStruct that you can join to your ActiveRecord or any other model.

Install

gem install static_record

Example usage

Create model class

class Category < StaticRecord::Base
end

and in the same directory provide file called categories.yml

1:
  name: Watches
  description: We make vibrant and bold watches for vibrant and bold people

2:
  name: Jewelery
  description: We have a range of original chunky silver jewellery including pendants from the Poseidon collection such as the Easter Island pendant

and you're all set:

>> pp Category.all
=> {1=>#<Category ...>, 2=>#<Category ...>}

>> c = Category.find(1)
=> #<Category description="We make vibrant and bold watches for vibrant and bold people", name="Watches", id=1>

>> c.name
=> "Watches"

Credits

Author: Dejan Simic