Skip to content

Instantly share code, notes, and snippets.

01:57:03 < knowtheory> tarcieri: i'm reading through the original presentation that that negative piece of criticism was pulled from
01:57:22 < knowtheory> And i would like to note that Perl has a Perl::Tidy lib ;)
01:57:34 < knowtheory> that the presentation calls a "Perl code beautifier"
01:57:55 < knowtheory> which... is a bit of a strange concept for ruby, since if your code is illegible, it's probably wrong anyway :P
01:58:19 < knowtheory> so, they can troll all they want about # of tests :P
01:58:35 < knowtheory> (and the original presentation is clearly not about trolling other languages, which is nice)
01:59:52 < knowtheory> also, it's worth noticing that the Perl Test suite took 5 years to go from 26,725 tests to 78,883
01:59:57 < knowtheory> and they built a freaking VM in the mean time :P
>> hash = {}
=> {}
>> [["one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty"],(1..20).to_a].transpose.each{ |key,value| hash[key] = value }
=> [["one", 1], ["two", 2], ["three", 3], ["four", 4], ["five", 5], ["six", 6], ["seven", 7], ["eight", 8], ["nine", 9], ["ten", 10], ["eleven", 11], ["twelve", 12], ["thirteen", 13], ["fourteen", 14], ["fifteen", 15], ["sixteen", 16], ["seventeen", 17], ["eighteen", 18], ["nineteen", 19], ["twenty", 20]]
>> hash
=> {"fifteen"=>15, "fourteen"=>14, "five"=>5, "three"=>3, "two"=>2, "eighteen"=>18, "seven"=>7, "six"=>6, "twelve"=>12, "eight"=>8, "nineteen"=>19, "thirteen"=>13, "eleven"=>11, "twenty"=>20, "sixteen"=>16, "one"=>1, "seventeen"=>17, "ten"=>10, "nine"=>9, "four"=>4}
>> arr = %w(four twelve nineteen seven fifteen)=> ["four", "twelve", "nineteen", "seven", "fifteen"]
>> arr.sort_by{ |w| hash[w] }
=> ["four", "seven", "twelve", "fifteen", "nineteen"
umbra:dm-spec ted$ irb
>> require 'dm-core'
=> true
>> require 'many_through_models'
=> true
>>
?> DataMapper.setup(:default, "mysql://localhost/dm_pets")
=> #<DataMapper::Adapters::MysqlAdapter:0x1903868 @resource_naming_convention=DataMapper::NamingConventions::Resource::UnderscoredAndPluralized, @uri=#<struct DataObjects::URI scheme="mysql", user=nil, password=nil, host="localhost", port=nil, path="/dm_pets", query=nil, fragment=nil>, name:default, transactions{}, field_naming_conventionDataMapper::NamingConventions::Field::Underscored
>> Human.all(Human.ownerships.pet.name => "Bo")
=> [#<Human id=1 first_name="Barack" middle_name=nil last_name="Obama">, #<Human id=2 first_name="Michelle" middle_name=nil last_name="Obama">, #<Human id=3 first_name="Malia" middle_name=nil last_name="Obama">, #<Human id=4 first_name="Sasha" middle_name=nil last_name="Obama">]
..FFFFFF.
1)
NoMethodError in 'behavior i expect out of an orm should have finders which return on in property models'
undefined method `not' for :middle_name:Symbol
./spec_many_through.rb:56:
2)
MysqlError in 'behavior i expect out of an orm should be able to find things by properties on immediate child models'
(mysql_errno=1066, sql_state=42000) Not unique table/alias: 'humans'
>> @barney = Pet.first(:name => "Barney")
=> #<Pet id=2 name="Barney" kind="Scottish Terrier Dog">
>> @barney.toys
=> []
>> @barney.toys << Toy.get(1)
=> [#<Toy id=1 name="Chew Toy" price=nil>]
>> @barney.save
=> true
>> @barney.toys
=> [#<Toy id=1 name="Chew Toy" price=nil>]

Contributing to DataMapper: A HowTo

DataMapper is a complex piece of technology. It's modularity creates a tremendous flexibility and potential, but it is also important that we constrain ourselves from that full flexibility, and provide a shared consensus on how DataMapper should be tested and developed.

DataMapper as you may know is divided up into dm-core and dm-more. Core is where the heavy lifting and shared code lies, more is where additional features that plug into Core reside, along with a few additional adapters.

This post is intended to explain how to test core, so that others might be able to join in and contribute.

Testing dm-core isn't an easy business. DataMapper's core classes and modules exist here, and ultimately need to be tested against all the included storage engines that are supported by DataMapper out of the box (in memory, yaml, sqlite3, mysql, postgres). However this is rather unwieldy when attempting to tighten the Test-Code cycle, since the specs take a long time to run.

gem 'dm-core', '0.10'
require 'dm-core'
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, 'sqlite3::memory:')
letters = %w(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z)
letters.each_with_index do |letter,index|
belong_classes, has_classes = letters.partition{ |other_letter| letters.rindex(other_letter) <= letters.rindex(letter) }
belong_string = belong_classes.map do |c|
"\tbelongs_to :#{c.downcase}" unless c == letter

Good news everyone!

We at Videojuicer are currently working on our next-generation API product, and we have a vacancy for a Ruby application developer to join our small team.

Our product is an API-led platform for generating leads from online video. It's designed to work in any situation where you have a video, and want it to drive traffic back to your product. That means it's good for screencasts, movie trailers, music videos, product commercials - you name it.

Our environment is a distributed team in the UK, US and Canada. We communicate mainly with Skype. Your working hours will be flexible, and you'll be able to work from your home, our London office or from a Brighton coworking venue if you so choose.

We work with Merb/Rails/Rack, DataMapper, Flex, Git, and jQuery. We use a series of futuristic moon-standards including HTML5, OAuth, OEmbed and SMIL3.

>> bo = Pet.get 1
Sat, 02 May 2009 04:53:31 GMT ~ debug ~ (0.000099) SET sql_auto_is_null = 0
Sat, 02 May 2009 04:53:31 GMT ~ debug ~ (0.000093) SET SESSION sql_mode = 'ANSI,NO_AUTO_VALUE_ON_ZERO,NO_DIR_IN_CREATE,NO_ENGINE_SUBSTITUTION,NO_UNSIGNED_SUBTRACTION,TRADITIONAL'
Sat, 02 May 2009 04:53:31 GMT ~ debug ~ (0.000333) SELECT `id`, `name`, `kind` FROM `pets` WHERE (`id` = 1) ORDER BY `id` LIMIT 1
=> #<Pet id=1 name="Bo" kind="Portugese Water Dog">
>> bo.update_attributes(:name => "Bobobo")
Sat, 02 May 2009 04:54:00 GMT ~ debug ~ (0.040384) UPDATE `pets` SET `name` = 'Bobobo' WHERE (`id` = 1)
=> true
>> Pet.get(1)
Sat, 02 May 2009 04:54:12 GMT ~ debug ~ (0.000331) SELECT `id`, `name`, `kind` FROM `pets` WHERE (`id` = 1) ORDER BY `id` LIMIT 1
require 'dm-core'
require 'dm-core/core_ext/symbol'
require 'dm-validations'
require 'appengine-apis'
require 'appengine-apis/local_boot'
require 'dm-appengine'
DataMapper::Logger.new(STDOUT, :debug)
DataMapper.setup(:default, "app_engine://memory")