Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/softace/activerecord-tableless
Bringing together the different tableless model implementations into a single gem/plugin
https://github.com/softace/activerecord-tableless
Last synced: 3 months ago
JSON representation
Bringing together the different tableless model implementations into a single gem/plugin
- Host: GitHub
- URL: https://github.com/softace/activerecord-tableless
- Owner: softace
- License: other
- Fork: true (kennethkalmer/activerecord-tableless-models)
- Created: 2012-09-03T11:04:01.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2017-11-13T22:29:22.000Z (almost 7 years ago)
- Last Synced: 2024-07-17T22:54:50.995Z (4 months ago)
- Language: Ruby
- Homepage:
- Size: 106 KB
- Stars: 113
- Watchers: 6
- Forks: 41
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
ActiveRecord Tableless
======================[![Build Status](https://travis-ci.org/softace/activerecord-tableless.png)](http://travis-ci.org/softace/activerecord-tableless)
[![Dependency Status](https://gemnasium.com/softace/activerecord-tableless.png)](https://gemnasium.com/softace/activerecord-tableless)
[![Code Climate](https://codeclimate.com/github/softace/activerecord-tableless.png)](https://codeclimate.com/github/softace/activerecord-tableless)A single implementation of the ActiveRecord Tableless pattern for any
Rails project or other Ruby project that uses ActiveRecord.Why, why, why
-------------Why would you ever consider this gem as opposed to ActiveModel.
It all started in Rails 2 (see History section). In rails 2 ActiveModel did not exists. Nowadays rails 2.x series is no longer supported.
In Rails 3 there is an Active Model API, where you can use some
features of Active Record in other classes. Yehuda Katz has written
[a nice introduction about this](http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/).In Rails 4 basic features of the Active Model API can be activated
by including
[ActiveModel:Model](http://api.rubyonrails.org/classes/ActiveModel/Model.html)
in the model. Carlos Antônio has written
[a nice tutorial about this](http://blog.plataformatec.com.br/2012/03/barebone-models-to-use-with-actionpack-in-rails-4-0/).However neither the Active Model API (Rails 3) nor the
ActiveModel::Model (Rails 4) supports relations and nested attributes.Installation
------------ActiveRecord Tableless is distributed as a gem, which is how it should
be used in your app.Include the gem in your Gemfile:
gem "activerecord-tableless", "~> 1.0"
Supported Versions
------------------Supported ruby version are
* **2.2.x** series higher than 2.2.2
* **2.3.x** seriesIf you are using Ruby version < 2.2.2 you can use the gem version <
2.0 like thisgem "activerecord-tableless", "~> 1.0.0"
Supported ActiveRecord versions are
* **3.0.x** series
* **3.2.x** series
* **4.1.x** series
* **4.2.x** seriesIf you are using ActiveRecord 2.3.x series you can use the gem version <
2.0 like thisgem "activerecord-tableless", "~> 1.0.0"
You may be able to make it work with 3.1.x, but you should expect to
put some time in it.TODO
----* Support Rails 5.x series
Usage
-----Define a model like this:
class ContactMessage < ActiveRecord::Base
has_no_table
column :name, :string
column :email, :string
validates_presence_of :name, :email
endYou can now use the model in a view like this:
<%= form_for :message, @message do |f| %>
Your name: <%= f.text_field :name %>
Your email: <%= f.text_field :email %>
<% end %>And in the controller:
def message
@message = ContactMessage.new
if request.post?
@message.attributes = params[:message]
if @message.valid?
# Process the message...
end
end
endIf you wish (this is not recommended), you can pretend you have a succeeding database by using
has_no_table :database => :pretend_success
Development
-----------To start develop, please download the source code
git clone git://github.com/softace/activerecord-tableless.git
Install development libraries
sudo apt-get install -y libsqlite3-dev libxml2-dev libxslt-dev
When downloaded, you can start issuing the commands like
gem install bundler -v '~> 1.12.0'
bundle install
bundle update
bundle exec appraisal generate
bundle exec appraisal install
bundle exec appraisal rake allOr you can see what other options are there:
bundle exec rake -T
Publishing gem
--------------```
gem bump -v pre
```Verify everything is OK.
```
gem build activerecord-tableless.gemspec
```Verify everything is OK.
```
gem release -t
```History
-------Originally this code was implemented for Rails 2 by Kenneth
Kalmer. For Rails 3 the need for this functionality was reduced
dramatically due to the introduction of ActiveModel. But because the
ActiveModel does not support relations and nested attributes the
existence of this gem is still justified.For a history of technical implementation details feel free to take a
look in the git log :-)Copyright
---------Copyright (c) Jarl Friis. See LICENSE.txt for
further details.