No release in over 3 years
Low commit activity in last 3 years
This gem allows to add additional database-stored fields to your models
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 2.0.0
>= 1.3.5

Runtime

>= 3.0.0
 Project Readme

ActsAsMetadata

Dynamicly add unlimited number of indexed, searchable, validatable, strongly typed fields to your ActiveRecord models.

Installation

Add this line to your application's Gemfile:

gem 'acts_as_metadata'

And then execute:

$ bundle

Or install it manually:

$ gem install acts_as_metadata

Usage

Generate migration that creates metadata tables:

$ rails g metadata:migration

Add acts_as_metadata to your model:

class MyModel < ActiveRecord::Base
  acts_as_metadata
end

and create metadata_cache column to speed up metadata extraction:

rails g migration AddMetadataCacheToMyModels metadata_cache:text

Create metadata types in your database:

mt = MetadataType.create! :tag => :sample, :name => "Sample", :datatype => :string

Its ready to use:

m = MyModel.new
m.m_sample = 'some string'
m.save!

Add some validations or default value if you need:

mt.default   = 'some default string' 
mt.mandatory = true                   # presence validation
mt.regexp    = "[a-z]*"               # regexp validation
mt.values    = ['aaa', 'bbb', 'ccc']  # inclusion validation
mt.save!

There are more usage examples in spec directory.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request