./README in ambition-0.1.0 vs ./README in ambition-0.1.1

- old
+ new

@@ -4,19 +4,20 @@ I could tell you all about how awesome the internals are, or how fun it was to write, or how it'll make you rich and famous, but instead I'm just going to show you some examples. -The goal is this: write once, run with ActiveRecord, Sequel, DataMapper, whatever. Kind -of like Rack for databases. +The goal is this: write once, run with ActiveRecord, Sequel, DataMapper, +whatever. Kind of like Rack for databases. == Git It (Not with Git, though) $ sudo gem install ambition -y -This will suck in Ambition and its dependencies (ParseTree & ActiveRecord). It's fully usable -outside of Rails (I use it in a Camping app or two), as long as you're riding ActiveRecord. +This will suck in Ambition and its dependencies (ParseTree & ActiveRecord). +It's fully usable outside of Rails (I use it in a Camping app or two), as long +as you're riding ActiveRecord. To use with Rails, after installing the gem: $ cd vendor/plugins $ gem unpack ambition @@ -31,17 +32,19 @@ puts user.name end And that's it. -The key is the +each+ method. You build up a +Query+ using +select+, +first+, and +sort_by+, -then call +each+ on it. This'll run the query and enumerate through the results. Really, you -can use any Enumerable method: +map+, +each_with_index+, etc. +The key is the +each+ method. You build up a +Query+ using +select+, +first+, +and +sort_by+, then call +each+ on it. This'll run the query and enumerate +through the results. Really, you can use any Enumerable method: +map+, ++each_with_index+, etc. -Our +Query+ object has two useful methods: +to_sql+ and +to_hash+. With these, we can -check out what exactly we're building. Not everyone has +to_sql+, though. Mostly ignore -these methods and treat everything like you normally would. +Our +Query+ object has two useful methods: +to_sql+ and +to_hash+. With these, +we can check out what exactly we're building. Not everyone has +to_sql+, +though. Mostly ignore these methods and treat everything like you normally +would. See, +to_sql+: >> User.select { |m| m.name == 'jon' }.to_sql => "SELECT * FROM users WHERE users.`name` = 'jon'" @@ -50,11 +53,11 @@ => {:conditions=>"users.`name` = 'jon'"} == Limitations You can use variables, but any more complex Ruby (right now) won't work -inside your blocks. Just do it outside the block and assign it to a variable, okay? +inside your blocks. Just do it outside the block and assign it to a variable. Instead of: User.select { |m| m.date == 2.days.ago } Just do: @@ -83,12 +86,12 @@ User.select { |m| (m.name == 'jon' || m.name == 'rick') && m.age == 21 } "SELECT * FROM users WHERE ((users.`name` = 'jon' OR users.`name` = 'rick') AND users.`age` = 21)" == Associations -- select { |u| u.field == 'bob' && u.association.field == 'bob@bob.com' } -The +to_sql+ method doesn't work on associations yet, but that's okay: they can still query through -ActiveRecord just fine. +The +to_sql+ method doesn't work on associations yet, but that's okay: they can +still query through ActiveRecord just fine. User.select { |u| u.email == 'chris@ozmm.org' && u.profile.name == 'chris wanstrath' }.map(&:title) SELECT users.`id` AS t0_r0, ... FROM users LEFT OUTER JOIN profiles ON profiles.user_id = users.id WHERE ((users.`email` = 'chris@ozmm.org' AND profiles.name = 'chris wanstrath')) == Comparisons -- select { |u| u.age > 21 } @@ -170,6 +173,6 @@ Found a bug? Sweet. Add it at the Lighthouse: http://err.lighthouseapp.com/projects/466-plugins/tickets/new Feature requests are welcome. -* Chris Wanstrath [ chris@ozmm.org ] +* Chris Wanstrath [ chris@ozmm.org ] \ No newline at end of file