Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
CouchRest implementation of Roles generic for CouchDB
Ruby
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
sandbox
spec
.document
.gitignore
.rspec
LICENSE
README.textile
Rakefile
VERSION

README.textile

Roles CouchRest

Implements the Roles Generic for CouchRest

See CouchRest CouchDB close to the metal and CouchDB with CouchRest in 5 minutes

See sandbox/test_db_conn.rb for example.

See view_objects for how to Query

design do
  view :by_title
  view :by_posted_at_and_title
  view :tag_list,
    :map =>
      "function(doc) {
        if (doc['model'] == 'Post' && doc.tags) {
          doc.tags.forEach(function(tag){
            emit(doc.tag, 1);
          });
        }
      }",
    :reduce =>
      "function(keys, values, rereduce) {
        return sum(values);
      }"
end

# Prepare a query:
view = Post.by_posted_at_and_title.skip(5).limit(10)

# Fetch the results:
view.each do |post|
  puts "Title: #{post.title}"
end

# Grab the CouchDB result information with the same object:
view.total_rows   => 10
view.offset       => 5

# Re-use and add new filters
filter = view.startkey([1.month.ago]).endkey([Date.current, {}])

# Fetch row results without the documents:
filter.rows.each do |row|
  puts "Row value: #{row.value} Doc ID: #{row.id}"
end

# Lazily load documents (take last row from previous example):
row.doc      => Fetch last Post document from database

# Using reduced queries is also easy:
tag_usage = Post.tag_list.reduce.group_level(1)
tag_usage.rows.each do |row|
  puts "Tag: #{row.key}  Uses: #{row.value}"
end

Generic Role strategies implemented:

Single role:

  • admin_flag
  • role_string
  • one_role

Multiple roles:

  • many_roles
  • roles_mask
  • role_strings

Install

gem install roles_couchrest

Use in Rails 3

in Gemfile
gem 'roles_couchrest'

Run $ bundle install

Usage

See Roles Generic API README and the specs included.

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don’t break it in a
    future version unintentionally.
  • Commit, do not mess with rakefile, version, or history.
    (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright © 2010 Kristian Mandrup. See LICENSE for details.

Something went wrong with that request. Please try again.