This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Make it possile for euro symbol to display properly | |
#DANGEROUS, AS IT BREAKS RUBY STRING METHODS | |
## | |
$KCODE = "u" | |
## | |
class Currency | |
#format hash: containing the symbol, thousands (and higher) delimiter and decimal | |
#usd_rate: some ratio when compaired to the dollar (ie the dollar is always 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form method="GET" action="http://localhost:2000/grove/shop/query/" | |
id="first" name="first"> | |
<input type="hidden" name="query" id="query" | |
value ='{ "query" : | |
[ {"columns" : [ "item" ]}, | |
{"operations" : [{"eq" : {"item" : { "string" : "orange"}}}]}, | |
{"order": "descending" } | |
] | |
}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PostQuery < Query | |
@@clauses = [:columns, :operations, :order] | |
def initialize(target_object) | |
super(target_object, @@clauses) | |
end | |
@@clauses.each do |c| | |
define_method(c){ self[c] } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Query.build do | |
view [:foo, :bar, :baz] | |
where do | |
:foo.eq "value" | |
:bar.gt 3 | |
:baz.in ["value", 3, :value] | |
end | |
order asc | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Query.build do | |
view [:foo, :bar, :baz] | |
where do | |
:foo.match /someregex/ | |
end | |
order asc | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Query.build do | |
view [:foo, :bar, :baz] | |
where do | |
:foo.is == "value" | |
:bar.is > 3 | |
:baz.is.in ["value", 3, :value] | |
end | |
order asc | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class OperationSerializer | |
def initialize(op) | |
@op | |
end | |
['==', '>', '>=', '<', '<='].each do |operator| | |
define_method(operator) do |val| | |
"#{@op} #{operator} #{val}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#what if you could write a query in rails that looked like ... | |
@users = Users.where do | |
:age.from {13 => 26} | |
end | |
#or | |
@events = Events.where do | |
:date.is.in ["02/10/2009", "02/11/2009", "03/15/2009"] | |
:num_seats.is.between [3, 12] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Zoo.find(:all, :conditions => ['num_employees between ? and ?', 100 , 300]) | |
Zoo.find(:all, :conditions => ['name = ?', 'Dallas']) | |
User.find(:first, :conditions => ['age between ? and ?', 10, 20]) | |
Zoo.where do | |
:num_employees.is.between [100, 300] | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
. | |
|-- lib | |
| |-- redquery | |
| | |-- active_record | |
| | | `-- base.rb | |
| | |-- active_record.rb | |
| | |-- adapters | |
| | | |-- adapter.rb | |
| | | `-- mysql.rb | |
| | |-- adapters.rb |