Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Converted to gem.

  • Loading branch information...
commit 128147efb4ca3ce50a3c30b74e34081b926a1eb7 1 parent 2af6aa5
Alex Fortuna authored
View
4 .gitignore
@@ -10,4 +10,6 @@
.ref*/
# Project-specific.
-dev/
+/dev/
+/pkg/
+README.html
View
33 README.md
@@ -6,9 +6,7 @@ SmartTuple: A Simple Yet Smart SQL Conditions Builder
Introduction
------------
-Sometimes we need to build SQL WHERE statements which are compound or conditional by nature, e.g. ones used by search forms.
-
-SmartTuple simplifies this task by letting us build statements of virtually unlimited complexity out of smaller ones.
+Sometimes we need to build SQL WHERE statements which are compound or conditional by nature. SmartTuple simplifies this task by letting us build statements of virtually unlimited complexity out of smaller ones.
SmartTuple is suitable for use with Ruby on Rails (ActiveRecord) and other Ruby frameworks and ORMs.
@@ -16,13 +14,30 @@ SmartTuple is suitable for use with Ruby on Rails (ActiveRecord) and other Ruby
Setup
-----
- script/plugin install git://github.com/dadooda/smart_tuple.git
+ gem install smart_tuple
+
+In your app's `config/environment.rb` do a:
+
+ config.gem "smart_tuple"
+
+
+Kickstart Demo
+--------------
+
+ tup = SmartTuple.new(" AND ")
+ tup << {:brand => params[:brand]} if params[:brand].present?
+ tup << ["min_price >= ?", params[:min_price]] if params[:min_price].present?
+ tup << ["max_price <= ?", params[:max_price]] if params[:max_price].present?
+
+ @phones = Phone.find(:all, :conditions => tup.compile)
+
+There's a number of ways you can use SmartTuple depending on the situation. They are covered in the tutorial below.
Tutorial
--------
-Suppose we've got a mobile phone catalog with a simple form which lets our users search through catalog. We are starting with a price filter of two values: `min_price` and `max_price`, both optional.
+Suppose we've got a mobile phone catalog with a search form. We are starting with a price filter of two values: `min_price` and `max_price`, both optional.
Filter logic:
@@ -171,7 +186,7 @@ Here's a brief cheatsheet, which outlines main SmartTuple features.
# Another SmartTuple.
tup << other_tuple
- # String. Generally NOT recommended.
+ # String.
tup << "brand IS NULL"
Appending empty or blank (where appropriate) statements has no effect on the receiver:
@@ -213,19 +228,19 @@ _This chapter still has to be written._
### Clearing ###
-If for some reason you want to put tuple into its initial state, do a:
+To put tuple into its initial state, do a:
tup.clear
### Compiling ###
-_Compiling_ is converting the tuple into something suitable for use as `:conditions` of an ActiveRecord call.
+Compiling is converting the tuple into something suitable for use as `:conditions` of an ActiveRecord call.
It's as straight as:
tup.compile
- tup.to_a # An alias.
+ tup.to_a # An alias, does the same.
# Go fetch!
Phone.find(:all, :conditions => tup.compile)
View
51 Rakefile
@@ -0,0 +1,51 @@
+require "rake/rdoctask"
+
+GEM_NAME = "smart_tuple"
+
+begin
+ require "jeweler"
+ Jeweler::Tasks.new do |gem|
+ gem.name = GEM_NAME
+ gem.summary = "A Simple Yet Smart SQL Conditions Builder"
+ gem.description = "A Simple Yet Smart SQL Conditions Builder"
+ gem.email = "alex.r@askit.org"
+ gem.homepage = "http://github.com/dadooda/smart_tuple"
+ gem.authors = ["Alex Fortuna"]
+ gem.files = FileList[
+ "[A-Z]*.*",
+ "*.gemspec",
+ "generators/**/*",
+ "lib/**/*.rb",
+ "init.rb",
+ ]
+ end
+rescue LoadError
+ STDERR.puts "This gem requires Jeweler to be built"
+end
+
+desc "Rebuild gemspec and package"
+task :rebuild => [:gemspec, :build]
+
+desc "Push (publish) gem to RubyGems (aka Gemcutter)"
+task :push => :rebuild do
+ # Yet found no way to ask Jeweler forge a complete version string for us.
+ vh = YAML.load(File.read("VERSION.yml"))
+ version = [vh[:major], vh[:minor], vh[:patch]].join(".")
+ pkgfile = File.join("pkg", [GEM_NAME, "-", version, ".gem"].to_s)
+ system("gem", "push", pkgfile)
+end
+
+desc "Compile README preview"
+task :readme do
+ require "kramdown"
+
+ doc = Kramdown::Document.new(File.read "README.md")
+
+ fn = "README.html"
+ puts "Writing '#{fn}'..."
+ File.open(fn, "w") do |f|
+ f.write(File.read "dev/head.html")
+ f.write(doc.to_html)
+ end
+ puts ": ok"
+end
View
4 VERSION.yml
@@ -0,0 +1,4 @@
+---
+:major: 0
+:minor: 1
+:patch: 0
View
46 smart_tuple.gemspec
@@ -0,0 +1,46 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE
+# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{smart_tuple}
+ s.version = "0.1.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Alex Fortuna"]
+ s.date = %q{2010-07-18}
+ s.description = %q{A Simple Yet Smart SQL Conditions Builder}
+ s.email = %q{alex.r@askit.org}
+ s.extra_rdoc_files = [
+ "README.html",
+ "README.md"
+ ]
+ s.files = [
+ "README.html",
+ "README.md",
+ "VERSION.yml",
+ "init.rb",
+ "lib/smart_tuple.rb",
+ "smart_tuple.gemspec"
+ ]
+ s.homepage = %q{http://github.com/dadooda/smart_tuple}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.5}
+ s.summary = %q{A Simple Yet Smart SQL Conditions Builder}
+ s.test_files = [
+ "spec/spec_helper.rb",
+ "spec/smart_tuple_spec.rb"
+ ]
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ else
+ end
+ else
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.