resource = Resource.new attributes
resource.valid? # => true | false
resource.save # => true | false Will raise adapter errors in case of Inconsistency
resource.errors # => ErrorSet (cached) will not reflect adapter errors
resource.attribute=invalid_value
resource.errors # Same error Set as above, will not reflect attribute change
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
Gemfile.lock |
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
require 'rubygems' | |
require 'backports' # aliases Proc#=== to Proc#call | |
rs = (0..10000).to_a.sample(30) | |
rs.each do |r| | |
case | |
when r.zero? then puts "#{r} is zero" | |
when (r % 5).zero? then puts "#{r} is fiven" | |
when (r % 4).zero? then puts "#{r} is fourven" |
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
require 'set' | |
require 'tsort' | |
module DataMapper | |
class Query | |
class Graph | |
include TSort | |
def initialize | |
@graph = Hash.new { |graph, target| graph[target] = Set.new } |
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
# NOTE: this is a code spike, and the following code will probably | |
# not make it into dm-core in it's current form. I wanted to see if it | |
# were possible to use a topographical sort to ensure parents were | |
# saved before children, before/after filters were fired in the correct | |
# order, and foreign keys set before children are saved, but after parents | |
# are saved. | |
# The hooks should fire in the following order: | |
# https://gist.github.com/6666d2818b14296a28ab |
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
require "rubygems" | |
require "datamapper" | |
DataMapper.setup(:default, "sqlite::memory:") | |
DataMapper::Logger.new(STDOUT, :debug) | |
class Recipe | |
include DataMapper::Resource | |
property :id, Serial |
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
$.extend({ | |
param: function( a, nest_in ) { | |
var s = [ ]; | |
// check for nest | |
if (typeof nest_in == 'undefined') nest_in = false; | |
function nested(key) { | |
if (nest_in) | |
return nest_in + '[' + key + ']'; | |
else |
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
// Shared Experience textarea blocker | |
$('#experience textarea#experience_body').bind('keypress', function(){ | |
$('a').attr('rel', 'blocked'); | |
}); | |
// Be alert! The world needs more Lerts. | |
$('a[rel="blocked"]').click(function(){ | |
alert('Sorry, This is just a demo!'); | |
return false; | |
}); |