Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

We have rdoc fun, yais?

commit 7ffcd8653a4766ce625e6f741a76069ff50d15df 1 parent 5e36315
@technicalpickles technicalpickles authored committed
View
24 lib/ambition/api.rb
@@ -1,4 +1,8 @@
module Ambition #:nodoc:
+ # Module that you will extend from in your adapters in your toplevel file.
+ #
+ # For example, for ambitious_sphinx in lib/ambition/adapters/ambitious_sphinx.rb, we have:
+ # ActiveRecord::Base.extend Ambition::API
module API
include Enumerable
@@ -14,6 +18,7 @@ def sort_by(&block)
context << Processors::Sort.new(context, block)
end
+ # Entries that our context is able to find.
def entries
ambition_context.kick
end
@@ -31,45 +36,60 @@ def slice(start, length = nil)
##
# Convenience methods
+
+ # See Enumerable#detect
def detect(&block)
select(&block).first
end
+ # See Array#first
def first(count = 1)
sliced = slice(0, count)
count == 1 ? Array(sliced.kick).first : sliced
end
+ # See Array#each, applied to +entries+
def each(&block)
entries.each(&block)
end
+ # See Enumerable#any?
def any?(&block)
select(&block).size > 0
end
+ # See Enumerable#all?
def all?(&block)
size == select(&block).size
end
+ # See Array#empty?
def empty?
size.zero?
end
- ##
- # Plumbing
+
+ # Builds a new +Context+.
def ambition_context
Context.new(self)
end
+ # Gives you the current ambitious adapter.
def ambition_adapter
name = respond_to?(:name) ? name : self.class.name
parent = respond_to?(:superclass) ? superclass : self.class.superclass
@@ambition_adapter[name] || @@ambition_adapter[parent.name]
end
+
+ # Assign the ambition adapter. Typically, you use this in the toplevel file of your adapter.
+ #
+ # For example, for ambitious_sphinx, in our lib/ambition/adapters/ambitious_sphinx.rb:
+ #
+ # ActiveRecord::Base.ambition_adapter = Ambition::Adapters::AmbitiousSphinx
def ambition_adapter=(klass)
@@ambition_adapter ||= {}
+ # should this be doing the same check for respond_to?(:name) like above?
@@ambition_adapter[name] = klass
end
View
2  lib/ambition/context.rb
@@ -34,10 +34,12 @@ def initialize(owner)
@stash = {}
end
+ # Gets the ambition_context. From a Ambition::Context, this is actually +self+.
def ambition_context
self
end
+ # Adds a clause to this context.
def <<(clause)
@clauses[clause.key] ||= []
@clauses[clause.key] << clause.to_s
View
1  lib/ambition/core_ext.rb
@@ -1,3 +1,4 @@
+# Object extensions to make metaprogramming a little easier.
class Object
def metaclass; (class << self; self end) end
def meta_eval(&blk) metaclass.instance_eval(&blk) end
Please sign in to comment.
Something went wrong with that request. Please try again.