Findable
Redis wrapper with API like ActiveRecord.
Requirements
- Redis
Installation
Add this line to your application's Gemfile:
gem "findable"
And then execute:
$ bundle
Setup config file and seed script:
$ rails generate findable:install
Added following files:
config/initializers/findable.rb
- Config file for Findable.
db/findable_seeds.rb
- Seed script for Findable.
db/findable_seeds/.keep
- Directory for storing seed files of Findable.
Usage
Create seed file if static data.
Example db/findable_seeds/tags.yml
:
data1:
id: 1
name: Ruby
Create model.
Example app/models/tag.rb
:
class Tag < Findable::Base
end
Execute seed script if you create seed files.
$ rake findable:seeds
Manipulate data with API like ActiveRecord.
$ rails console
pry(main)> Tag.find(1)
=> #<Tag:0x00000108068430 @_attributes={:id=>1, :name=>"Ruby"}>
pry(main)> golang = Tag.create(name: "Go")
=> #<Tag:0x00000107ff6420 @_attributes={:name=>"Go", :id=>2}>
pry(main)> Tag.all.each {|tag| p tag.name }
"Ruby"
"Go"
=> [#<Tag:0x00000107f49568 @_attributes={:id=>1, :name=>"Ruby"}>, #<Tag:0x00000107f492e8 @_attributes={:name=>"Go", :id=>2}>]
Associations
It is possible to use the belongs_to
and has_one
and has_many
.
Mutually can refer to objects of ActiveRecord and Findable.
class Article < ActiveRecord::Base
include Findable::Associations::ActiveRecordExt
belongs_to :tag
end
class Tag < Findable::Base
has_many :articles
end
Contributing
- Fork it ( https://github.com/i2bskn/findable/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request