Skip to content

Instantly share code, notes, and snippets.

View paul's full-sized avatar

Paul Sadauskas paul

View GitHub Profile
require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb')
describe Templates, "index action" do
before :all do
create_template_xml 'simple', <<-"XML"
<template name="simple" description="The simplest template possible" />
XML
end
before do
You can specify how many times you want to run the benchmarks with rake:perf x=(number)
Some tasks will be run 10 and 1000 times less than (number)
Benchmarks will now run 10000 times
| DM 0.9.4 | AR 2.1 | DIFF |
--------------------------------------------------------------------------------
Model.get specific (not cached) x10000 | 29.548 | 15.131 | 1.95x |
Model.get specific (cached) x10000 | 1.573 | 15.245 | 0.10x |
Model.first x10000 | 22.623 | 14.991 | 1.51x |
Model.all limit(100) x1000 | 28.172 | 31.094 | 0.91x |
Model.all limit(10,000) x10 | 26.626 | 33.923 | 0.78x |
diff --git a/lib/dm-core/resource.rb b/lib/dm-core/resource.rb
index 225200d..8eb59bf 100644
--- a/lib/dm-core/resource.rb
+++ b/lib/dm-core/resource.rb
@@ -40,6 +40,10 @@ module DataMapper
model.const_set('Resource', self) unless model.const_defined?('Resource')
extra_inclusions.each { |inclusion| model.send(:include, inclusion) }
descendants << model
+ class << model
+ @_valid_model = false
@paul
paul / gist:9982
Created September 10, 2008 18:10
Before Yehuda's commit ( e253765ed82aa91cc91555eb5871d82d5df3e436 ):
| DM 0.9.4 | AR 2.1 | DIFF |
--------------------------------------------------------------------------------
Model.new (instantiation) x10000 | 0.949 | 0.568 | 1.67x |
Model.new(setting attributes) x10000 | 2.757 | 2.233 | 1.23x |
Before _monki's fix ( db6c116af073ad5cd219652366f2ef4fb47ef807 ):
| DM 0.9.4 | AR 2.1 | DIFF |
{
:_type => Template,
:id => template.path,
:href => uri(:controller => :templates, :action => template.path),
:name => template.name,
:description => template.description,
:max_associations_per_configuration => template.max_associations_per_configuration,
:questions_href => questions_url(template),
:restricted_platforms => template.restricted_platforms,
:restricted_clients => template.restricted_clients
We couldn’t find that file to show.

RubyJson Merb Views

Given this model (DataMapper):

class Article
  include DataMapper::Resource

  property :id,       Serial
  property :uuid,     UUID

property :title, String

{
"href": "http://config.ssbe.localhost/templates",
"item_count": 1,
"items": [
{
"id": "os/linux/linux-core",
"href": "http://config.ssbe.localhost/templates/os/linux/linux-core",
"name": "Linux Core",
"description": "CPU and other general Linux metrics",
"max-associations-per-configuration": 1
@paul
paul / uuid.rb
Created September 25, 2008 22:26
require 'rubygems'
require 'uuidtools'
module DataMapper
module Types
class UUID < DataMapper::Type
default lambda { ::UUID.random_create }
def self.load(value, property)
puts value.inspect
describe 'creating a article by web services' do
before do
@result = post('/articles', '{ "title": "My Article", "text": "Lorem Ipsum" }', :content_type => 'application/json')
@article_uri = @result.header['Location']
id = parse_route(@article_uri)[:id]
@article = Article.get(id)
end
it 'should be successful' do