This file contains hidden or 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
| include 'dm-is-list' | |
| class Node | |
| include DataMapper::Resource | |
| property :id, Serial | |
| # other properties... | |
| has n, :parts | |
| end |
This file contains hidden or 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
| # As an exercise, come up with a ruby-way to specify | |
| # a set of search conditions for this SQL: | |
| # simple or | |
| # WHERE name = 'Dan' OR name = 'Paul' | |
| # nested or, plus duplicating field names | |
| # WHERE name = 'Paul' AND ( age < 18 OR age > 21 ) | |
| # not ( and don't say != ) |
This file contains hidden or 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
| rake spec results: | |
| MySQL | |
| 102 examples, 1 failure, 1 pending | |
| Postgres | |
| 114 examples, 10 failures, 1 pending | |
| SQLite3 | |
| SQlite3 -- database locked |
This file contains hidden or 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
| require 'dm-core' | |
| require 'dm-types' | |
| class CrawledURI | |
| include DataMapper::Resource | |
| storage_names[:default] = 'crawled_uris' | |
| property :id, Serial |
This file contains hidden or 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
| post '/user/permissions' do | |
| require_permission_to 'administer permissions' | |
| params[:permissions].each do |role_id, permission_ids| | |
| next unless role = Role.get(role_id) | |
| role.update(:permissions => Permission.all(:id => permission_ids.keys)) | |
| end | |
| redirect '/user/permissions' | |
| end |
This file contains hidden or 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
| #!/usr/bin/env ruby -Ku | |
| require 'rubygems' | |
| require 'dm-core' | |
| require 'dm-sweatshop' | |
| require 'bacon' | |
| #DataMapper::Logger.new($stdout, :debug) | |
| DataMapper.setup(:default, 'sqlite3::memory:') |
This file contains hidden or 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
| #!/usr/bin/env ruby -Ku | |
| # encoding: utf-8 | |
| require 'rubygems' | |
| require 'dm-core' | |
| DataMapper::Logger.new($stdout, :debug) | |
| DataMapper.setup(:default, 'mysql://localhost/dm_core_test') |
This file contains hidden or 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
| #!/usr/bin/env ruby -Ku | |
| # encoding: utf-8 | |
| require 'rubygems' | |
| require 'dm-core' | |
| DataMapper::Logger.new($stdout, :debug) | |
| DataMapper.setup(:default, 'sqlite3::memory:') |
This file contains hidden or 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
| #!/usr/bin/env ruby -Ku | |
| # encoding: utf-8 | |
| require 'rubygems' | |
| require 'dm-core' | |
| DataMapper::Logger.new($stdout, :debug) | |
| DataMapper.setup(:default, 'sqlite3::memory:') |
This file contains hidden or 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
| require 'rubygems' | |
| require 'backports' # aliases Proc#=== to Proc#call | |
| rs = (0..10000).to_a.sample(30) | |
| rs.each do |r| | |
| case r | |
| when lambda { |n| n.zero? } then puts "#{r} is zero" | |
| when lambda { |n| (n % 5).zero? } then puts "#{r} is fiven" | |
| when lambda { |n| (n % 4).zero? } then puts "#{r} is fourven" |
OlderNewer