GithubHelp home page GithubHelp logo

chaingang's Introduction

Introduction

Chainable APIs are great. There's no denying it. With Rails 3, ActiveRecord got a chainable API. But not so for ActiveResource, that red-headed stepchild of the Rails 'verse.

Installation

It's a gem. Install it.

$ gem install chaingang

Usage

First, include ChainGang in your ActiveResource::Base derived client class.

class Article < ActiveResource::Base
  self.site = 'http://blah.com'
  include ChainGang
end

Then, go wild:

# find all the articles /articles/published.xml?author=moonmaster9000&genre=sci-fi
@articles = Article.find(:all).from(:published).where.author?("moonmaster9000").and.genre?("sci-fi")

# at this point, @articles hasn't actually made the network call yet. 
@articles.each do |article| # now it's made the network call
  puts article.title
end

# or, find a specific article by id, but add a "?preview_data=true" onto the query string.
@article = Article.find('some-article-id').where.preview_data?(true)

# or, find the first article by moonmaster9000 and get the title; /articles.xml?author=moonmaster9000
@article = Article.find(:first).where.author?("moonmaster9000").title

# to specifiy the reqeust format, you can use format() method, which temporarily set Article.format for this request.
@article = Article.find(:first).where.author?("moonmaster9000").format(:json)         # or :xml

Documentation

Checkout http://rdoc.info/gems/chaingang/frames

chaingang's People

Contributors

dorren avatar moonmaster9000 avatar

Stargazers

 avatar

Watchers

 avatar  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.