ruby-ext-js

Provides ultra-basic classes for translating Ext.js GET params to Postgres (via Datamapper) and MongoDB (via Mongood) query opts with sensible default limits.

Examples:

MongoDB

class PullRequests < ExtJs::Mongo
  def self.allowed_filters
    ["state"]
  end
end

mongo = PullRequests.new( params )
mongo.conditions # search conditions
mongo.options # pagination and sorting options

Postgres

(Implementation and API will change significantly in the future, don’t use this yet.)

module ExtJs
  class PullRequests < Postgres
    # Converts Ext.js' wacky params structure into a Postgres db query opts
    # hash. Supports filtering by PullRequests.state only
    def self.db_opts(params, opts = {})
      params[:dir] ||= "DESC" # Default to descending order

      db_opts = self.pagination_opts( params, {
        :max_offset => 5000, # Optional, prevent Postgres from shitting its pants
        :max_limit => 100
      }.merge( opts ))

      # Filters (the Ext filters hash is not pretty)
      filters = {}
      if params[:filter] && params[:filter]["0"] && params[:filter]["0"][:data]
        filters = case params[:filter]["0"][:data][:value]
          when "Rejected":   { :rejected => true }
          when "Approved":   { :rejected => false }
          when "Unreviewed": { :reviewed => nil }
        end
      end

      db_opts.merge filters
    end
  end
end

Specs

ExtJs was extracted from private code. Existing specs rely on private models, so there are no specs here yet. Specs will require DataMapper.

Contributing

Version history

Version number conventions: Patch-level bumps for bug fixes, minor-level bumps for changes that break backwards-compatibility, major-level bumps for major new features.

0.3.3

0.3.2

0.3.1

0.3.0

0.2.1

0.2.0

0.1.0

0.0.1

Copyright

Copyright © 2011 CrowdFlower. See LICENSE.txt for further details.