Skip to content

Instantly share code, notes, and snippets.

View djsun's full-sized avatar

David James djsun

View GitHub Profile
$ ruby api.rb
/opt/local/lib/ruby/gems/1.8/gems/mongomapper-0.2.0/lib/mongomapper.rb:58:in `database': uninitialized class variable @@database in MongoMapper (NameError)
from /opt/local/lib/ruby/gems/1.8/gems/mongomapper-0.2.0/lib/mongomapper/document.rb:113:in `database'
from /opt/local/lib/ruby/gems/1.8/gems/mongomapper-0.2.0/lib/mongomapper/document.rb:122:in `collection'
from /opt/local/lib/ruby/gems/1.8/gems/mongomapper-0.2.0/lib/mongomapper/embedded_document.rb:40:in `ensure_index'
from /Users/david/dev/datcat-api/models/source.rb:5
from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
from /opt/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:156:in `require'
from /opt/local/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/dependencies.rb:521:in `new_constants_in'
class Example
def start
puts "start self : #{self.inspect}"
Other.action
puts "start self : #{self.inspect}"
end
def callback
puts "callback self : #{self.inspect}"
end
In response to:
http://github.com/jnunemaker/mongomapper/issues/#issue/46
My setup:
* MongoDB nightly OSX 32 bit build.
* Gems (installed via 'sudo gem install ...')
* mongomapper (0.3.1)
* mongodb-mongo (0.10.1)
* mongodb-mongo_ext (0.4.1)
In response to:
http://github.com/jnunemaker/mongomapper/issues/#issue/46
My setup:
* MongoDB nightly OSX 32 bit build.
* mongomapper
* pulled from git://github.com/jnunemaker/mongomapper.git
* Gems (installed via 'sudo gem install ...')
* mongodb-mongo (0.10.1)
* mongodb-mongo_ext (0.4.1)
should "set updated_at on document update but leave created_at alone" do
doc = @document.create(:first_name => 'John', :age => 27)
old_created_at = doc.created_at
old_updated_at = doc.updated_at
sleep 1
@document.update(doc._id, { :first_name => 'Johnny' })
from_db = @document.find(doc.id)
from_db.created_at.to_i.should == old_created_at.to_i
from_db.updated_at.to_i.should_not == old_updated_at.to_i
end
class Comment < ActiveRecord::Base
belongs_to :post
end
require 'test_helper'
require 'models'
class BelongsToProxyTest < Test::Unit::TestCase
def setup
clear_all_collections
end
should "default to nil" do
status = Status.new
module Helper
def self.parent(scope)
chain = scope.name.split("::")[0 ... -1]
chain.reduce(Object) { |m, o| m.const_get(o) }
end
end
module Family
def sibling(string)
Helper.parent(self).const_get(string)
require 'rubygems'
require 'feedzirra'
# gem install feedzirra
url = "http://sunlightlabs.com/blog/feeds/tag/datacatalog/"
feed = Feedzirra::Feed.fetch_and_parse(url)
puts feed.title
puts feed.url
puts feed.feed_url
module Utility
# ActiveSupport 2.3.5 adds @_rails_html_safe aggressively.
# This method removes it so you can output clean YAML.
def self.plain_string(s)
if s.instance_variable_defined?(:@_rails_html_safe)
s.send(:remove_instance_variable, :@_rails_html_safe)
end
s
end