Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cmeiklejohn/materializer
Persist serialization in the model.
https://github.com/cmeiklejohn/materializer
Last synced: about 2 months ago
JSON representation
Persist serialization in the model.
- Host: GitHub
- URL: https://github.com/cmeiklejohn/materializer
- Owner: cmeiklejohn
- License: mit
- Created: 2011-07-12T03:05:25.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2011-09-23T04:43:31.000Z (over 13 years ago)
- Last Synced: 2024-10-26T08:55:37.039Z (2 months ago)
- Language: Ruby
- Homepage: https://github.com/cmeiklejohn/materializer
- Size: 98.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- License: LICENSE
Awesome Lists containing this project
README
= Materializer
Persist serialization in the model by front-loading the serialization
and storing in the database as a string.== Usage
Using Materializer is easy!
=== How to include an enable it?
It's easy. First, add the gem:
gem 'materializer'
Enable materializer in the models you which to maintain rendered views
in.include Materializer
Then, define one or more materialization profiles:
materialize :into => FIELD_NAME, :using => METHOD_NAME
You'll also need to make a migration to add the column:
t.string FIELD_NAME_json
Voila!
FIELD_NAME will be populated with the JSON generated from
METHOD_NAME on save. METHOD_NAME should be implemented as a
serializable_hash method returning a hash.=== Examples
Some examples on usage:
==== Materialize data into name_json using the name_as_json method.
materialize :into => :name, :using => :name_as_json
==== Materialize data into all_json using the as_json method.
materialize :into => :all, :using => :as_json
==== Pull in objects from other models
materialize :into => :all, :using => :all_as_json
def all_as_json
{ :field1 => field1, :association1 => association1.as_json }
end== License
Materializer is Copyright © 2011 Christopher Meiklejohn. It is free software, and may be redistributed under the terms specified in the LICENSE file.
== About
The materializer gem was written by {Christopher Meiklejohn}[mailto:[email protected]] from {Swipely, Inc.}[http://www.swipely.com].