Skip to content

Instantly share code, notes, and snippets.

View paul's full-sized avatar

Paul Sadauskas paul

View GitHub Profile
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.
{
"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

RubyJson Merb Views

Given this model (DataMapper):

class Article
  include DataMapper::Resource

  property :id,       Serial
  property :uuid,     UUID

property :title, String

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
@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
require 'dm-sweatshop'
require 'uuidtools'
Configuration.fixture {{
:uuid => UUID.random_create,
:name => /\w+/.gen[1..4],
:client_href => ("http://core.ssbe.localhost/clients/" + /\w+/.gen),
:notes => /[:sentence:]/.gen[0..140],
:platform => /\w+/.gen,
class Answers < Application
provides :sscj1
...
def show
raise "Oh noes!"
@answer = answer