Skip to content

Instantly share code, notes, and snippets.

Scotts-MacBook-Air-5:web(master) smtlaissezfaire$ dalek -l 5 dalek/*_test.js -d sauce
Running tests
☁ [SYSTEM] dalek-internal-driver: Loading driver: "sauce"
>> ERROR: TypeError: Cannot read property '0' of null
{
"driver": ["sauce"],
"driver.sauce": {
"user": "my-user-name",
"key": "my-key"
}
}
def first(options={})
return nil if ids.blank?
if sorted?
matched_ids = klass.collection.distinct(:_id, query(options).criteria.to_hash)
return nil if matched_ids.blank?
matched_ids.sort_by! { |matched_id| ids.index(matched_id) }
find!(matched_ids.first)
else
query(options).first
diff --git a/lib/mongo_mapper/plugins/counter_cache.rb b/lib/mongo_mapper/plugins/counter_cache.rb
index 7505b6b..92934cf 100644
--- a/lib/mongo_mapper/plugins/counter_cache.rb
+++ b/lib/mongo_mapper/plugins/counter_cache.rb
@@ -49,29 +49,48 @@ module MongoMapper
raise InvalidCounterCacheError, "You must define an association with name `#{association_name}' on model #{self}"
end
- association_class = association.klass
- key_names = association_class.keys.keys
class MyDBClass
def initialize(*args)
initer = MysqlInitializer.new(*args)
initer.init!
@database = initer.database
end
end
class MysqlInitializer
def initialize(
# Returns the parent feed of this feed item
# Warning, this method may be slow if you have a
# large number of FeedTools::Feed objects. Can't
# use a direct reference to the parent because it plays
# havoc with the garbage collector. Could've used
# a WeakRef object, but really, if there are multiple
# parent feeds, something is going to go wrong, and the
# programmer needs to be notified. A WeakRef
# implementation can't detect this condition.
def feed
--------------------------------------------------------- Fixnum#id2name
fix.id2name -> string or nil
------------------------------------------------------------------------
Returns the name of the object whose symbol id is _fix_. If there
is no symbol in the symbol table with this value, returns +nil+.
+id2name+ has nothing to do with the +Object.id+ method. See also
+Fixnum#to_sym+, +String#intern+, and class +Symbol+.
symbol = :@inst_var #=> :@inst_var
id = symbol.to_i #=> 9818
class Person
def initialize
register
end
attr_accessor :name
private
def register
>> class Foo; class << self; define_method(:bar) { :baz }; end; end
=> #<Proc:0x00361cf8@(irb):1>
>> Foo.bar
=> :baz
>>
class Foo; end
method_names = [:bar, :baz]
return_value = :quxx
Foo.class_eval do
metaclass = class << self; self; end
metaclass.instance_eval do
method_names.each do |method_name|