Coder Social home page Coder Social logo

model_set's Introduction

ModelSet

ModelSet is a array-like class for dealing with sets of ActiveRecord models. ModelSet stores a list of ids and fetches the models lazily only when necessary. You can also add conditions in SQL to further limit the set. Currently I support alternate queries using the Solr search engine through a subclass, but I plan to abstract this out into a “query engine” class that will support SQL, Solr, Sphinx, and eventually, other query methods (possibly raw RecordCache hashes and other search engines).

Usage:

class RobotSet < ModelSet
end

set1 = RobotSet.new([1,2,3,4]) # doesn't fetch the models

set1.each do |model| # fetches all
  # do something
end

set2 = RobotSet.new([1,2])

set3 = set1 - set2
set3.ids
# => [3,4]

set3 << Robot.find(5)
set3.ids
# => [3,4,5]

Install:

sudo gem install ninjudd-deep_clonable -s http://gems.github.com
sudo gem install ninjudd-ordered_set -s http://gems.github.com
sudo gem install ninjudd-model_set -s http://gems.github.com

License:

Copyright © 2009 Justin Balthrop, Geni.com; Published under The MIT License, see LICENSE

model_set's People

Contributors

ninjudd avatar lancepantz avatar scott-steadman avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.