Project

nevermind

0.0
No commit activity in last 3 years
No release in over 3 years
Working with multiple models like with one. @posts = Nevermind::Proxy.new(Article, Video).find_by(author: @author)
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
>= 0
~> 3.1
 Project Readme

Nevermind

Nevermind is purposed to proxy calls to multiple models

@post = Nevermind::Proxy.new(Article.all, Video.all).find_by(slug: @slug)

Installation

Add this line to your application's Gemfile:

gem 'nevermind'

And then execute:

$ bundle

Or install it yourself as:

$ gem install nevermind

Usage

@posts = Nevermind::Proxy.new(Article.all, Video.all)

As for version 0.0.2 it:

  • Supports calls to proxied class that expected to return item from collection. This is done by default.
  • Collection methods proxy
  • ActiveRecord relation methods proxy

Default behaviour

It delegates method calls to proxied classes if they not supposed to be "collection" or "relation methods".

When called returns not nil:

@posts.find_by(params) == Article.find_by(params) || Video.find_by(params)
@posts.first

The "!" methods will return result which doesn't raise exception:

@posts.find_by! params
@posts.first!

So, such method calls are class agnostioc.

Collection methods

Only each and [] is supported at the moment. They are also class-agnostic:

@posts.each { |post| post.do_something! }
@posts[3]

ActiveRecord relation methods

This methods can be used for ActiveRecord only

@posts.where(title: title)
      .each { |post| post.do_something! }
      
@posts.where(title: title)
      .order(:slug)
      .limit(10).offset(20)
      .each { |post| post.do_something! }

! Warning: params for ActiveRecord not yet carefully checked: be shure to pass ints to limit & offset

Future

  • Implement ActiveRecord method group for Mongoid
  • Support paginators like will_paginate & kaminari
  • Class syntax like
class Post < Nevermind::Something
    proxies Article
    proxies Video
end
  • Rails helpers like
<%= nevermind @post, article:'articles/_item', video:'videos/_item' %>

Contributing

  1. Fork it ( https://github.com/appelsin/nevermind/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request