Class: ShyCouch::Data::Design

Inherits:
CouchDocument show all
Defined in:
lib/ShyCouch/data.rb

Instance Method Summary collapse

Methods inherited from CouchDocument

all, #attr_keys, constraints, #delete!, #method_missing, #missing_needs, #missing_suggestions, needs, #needs, #needs?, #pull, #pull!, push_to, #respond_to?, #satisfies_needs?, #satisfies_suggestions?, #suggests, suggests, #suggests?, target_db, #to_hash, #to_json, #valid?

Constructor Details

#initialize(name, opts = {}) ⇒ Design

this is used to manage design documents In practise, the Controllers should be a list of classes corresponding to design documents



404
405
406
407
408
409
410
411
# File 'lib/ShyCouch/data.rb', line 404

def initialize(name, opts = {})
	merge! "_id" => "_design/#{name.to_s}"
	@parser = ShyRubyJS::ShySexpParser.new
	views = opts[:views] if opts[:views]
	merge_views(views) if views
	@database = opts[:push_to] if opts[:push_to]
	merge! "kind" => self.class.to_s.split("::").last
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ShyCouch::Data::CouchDocument

Instance Method Details

#add_view(view) ⇒ Object

Raises:

  • (TypeError)


417
418
419
420
421
# File 'lib/ShyCouch/data.rb', line 417

def add_view(view)
raise TypeError unless view.kind_of?(ShyCouch::Data::View)
@views << view
merge_views
end

#nameObject



413
414
415
# File 'lib/ShyCouch/data.rb', line 413

def name
return self["_id"].split("_design/").drop(1).join
end

#push!(opts = {}) ⇒ Object

Raises:



439
440
441
442
443
# File 'lib/ShyCouch/data.rb', line 439

def push!(opts = {})
opts[:push_to] ? db = opts[:push_to] : db = @database
raise ShyCouchError, "No CouchDB defined" unless db
db.add_design_and_push!(self)
end

#query_view(view, opts = {}) ⇒ Object

Raises:



423
424
425
426
427
428
429
430
431
432
433
# File 'lib/ShyCouch/data.rb', line 423

def query_view(view, opts = {})
if opts[:from]
	db = opts[:from]
else
	db = @database
end
raise ShyCouchError, "No CouchDB defined" unless db
view = view.name if view.kind_of?(ShyCouch::Data::View)
#TODO - something
db.query_view(self.name, view, opts)
end

#view(view_name, &block) ⇒ Object



435
436
437
# File 'lib/ShyCouch/data.rb', line 435

def view(view_name, &block)
add_view(ShyCouch::Data::View.new(view_name, &block))
end