2011-02-05 22:22:07 +01:00
|
|
|
|
|
|
|
#### NOTE Work in progress! Not yet used!
|
|
|
|
|
|
|
|
module CouchRest
|
|
|
|
module Model
|
|
|
|
|
|
|
|
# A design block in CouchRest Model groups together the functionality of CouchDB's
|
|
|
|
# design documents in a simple block definition.
|
|
|
|
#
|
|
|
|
# class Person < CouchRest::Model::Base
|
|
|
|
# property :name
|
|
|
|
# timestamps!
|
|
|
|
#
|
|
|
|
# design do
|
|
|
|
# view :by_name
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
#
|
2011-02-06 04:32:23 +01:00
|
|
|
module Designs
|
2011-02-05 22:22:07 +01:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
module ClassMethods
|
|
|
|
|
|
|
|
def design(*args, &block)
|
2011-02-06 02:52:09 +01:00
|
|
|
mapper = DesignMapper.new(self)
|
|
|
|
mapper.instance_eval(&block)
|
2011-02-05 22:22:07 +01:00
|
|
|
|
2011-02-06 02:52:09 +01:00
|
|
|
req_design_doc_refresh
|
2011-02-05 22:22:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
#
|
2011-02-06 02:52:09 +01:00
|
|
|
class DesignMapper
|
2011-02-05 22:22:07 +01:00
|
|
|
|
2011-02-06 02:52:09 +01:00
|
|
|
attr_accessor :model
|
2011-02-05 22:22:07 +01:00
|
|
|
|
2011-02-06 02:52:09 +01:00
|
|
|
def initialize(model)
|
|
|
|
self.model = model
|
|
|
|
end
|
2011-02-05 22:22:07 +01:00
|
|
|
|
2011-02-06 02:52:09 +01:00
|
|
|
# Define a view and generate a method that will provide a new
|
|
|
|
# View instance when requested.
|
|
|
|
def view(name, opts = {})
|
|
|
|
View.create(model, name, opts)
|
|
|
|
model.class_eval <<-EOS, __FILE__, __LINE__ + 1
|
|
|
|
def self.#{name}(opts = {})
|
2011-02-06 04:32:23 +01:00
|
|
|
CouchRest::Model::Designs::View.new(self, opts, '#{name}')
|
2011-02-06 02:52:09 +01:00
|
|
|
end
|
|
|
|
EOS
|
2011-02-05 22:22:07 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|