Skip to content

Instantly share code, notes, and snippets.

View solnic's full-sized avatar

Peter Solnica solnic

View GitHub Profile
@dkubb
dkubb / .rvmrc
Created August 10, 2011 22:44
Web framework Spike
rvm use @$(basename `pwd`) --create
# Untested, mind dump
class Document < ActiveRecord::Base
include Virtus
before_save :dump_attributes
after_initialize :load_attributes
private
@mbj
mbj / embedded_items.rb
Created June 6, 2011 13:50
Using veritas as a pseudo EV replacement in datamapper
# this is full of bad metaprogramming
class EmbeddedItems < DataMapper::Mongo::Property::Array
def load(value)
if value.nil?
nil
elsif value.is_a? ::Array
value.map { |item| embedded_item_class.load item }.extend collection
else
raise ArgumentError.new "+value+ of a property of #{self.class} type must be ::Array was: #{value.class}"
end
@solnic
solnic / dm-commits-report-2011-03-17.markdown
Created May 23, 2011 11:14
DataMapper commits between 1.1.0 and 1.1.1
| AR 3.0.7 | DM 1.1.1 | SQ 3.22.0 | DIFF_AR_VS_DM | DIFF_SQ_VS_DM |
--------------------------------------------------------------------------------------------------------------------------
Model#id x1000 | 0.004 | 0.000 | 0.000 | 13.79x | 0.64x |
Model.new (instantiation) x10 | 0.000 | 0.000 | 0.000 | 26.88x | 31.38x |
Model.new (setting attributes) x10 | 0.001 | 0.000 | 0.000 | 2.54x | 0.54x |
Model.get specific (not cached) x10 | 0.004 | 0.006 | 0.004 | 0.77x | 0.70x |
Model.get specific (cached) x10 | 0.004 | 0.001 | 0.004 | 5.70x | 4.77x |
Model.first x10 | 0.021 | 0.005 | 0.004 | 4.35x | 0.79x |
Model.all limit(100)
@solnic
solnic / TODO.markdown
Created March 25, 2011 13:02
This gist shows the status of EmbeddedValue development in dm-core and my notes
  • Integration Model shared specs for Resource/EV:

    • DataMapper::Model::Core
    • DataMapper::Model::Property
    • DataMapper::Model::Hook
    • DataMapper::Model::Relationship
  • Integration Resource shared specs for Resource/EV:

  • DataMapper::Resource::Attributes
@solnic
solnic / dm_property_2.0.rb
Created January 18, 2011 12:12
An introduction to DataMapper Property API v. 2.0 (draft)
##
#
# The most important aspect of the new Property API is that
# property inheritance should not be used to instruct
# adapters how to persist data. It means, for example, that
# you should not use Integer as the base class for your custom
# property just because it is persisted as an integer. Right now
# Enum inherits from Integer because it is stored as an integer.
# It is a mistake, because a value of Enum property can be either
# a string or a symbol, not integer. The fact that it is persisted
@fxn
fxn / gist:274219
Created January 11, 2010 13:05
seach for STI grandchildren who are leaves
# Computes STI models who are grandchildren or more.
#
# In a STI the root class and its subclasses work normally, but if there are
# grandchildren we need to preload them. Reason is, given A < B < C, if you
# for example compute B.count without loading A, only B records are taken into
# account in the query (where a clause about the type column intervenes). This
# is not a bug, Active Record is simply not aware of A. Once it is, the clause
# becomes an OR with all relevant types.
#
# I used this script to compute them.