Module: Sinatra::Rabbit::DSL

Included in:
Collection
Defined in:
lib/sinatra/rabbit/dsl.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.<<(c) ⇒ Object



54
55
56
# File 'lib/sinatra/rabbit/dsl.rb', line 54

def self.<<(c)
  register_collection(c)
end

.register_collection(c, &block) ⇒ Object



49
50
51
52
# File 'lib/sinatra/rabbit/dsl.rb', line 49

def self.register_collection(c, &block)
  @collections ||= []
  @collections << c
end

Instance Method Details

#[](collection) ⇒ Object



58
59
60
# File 'lib/sinatra/rabbit/dsl.rb', line 58

def [](collection)
  collections.find { |c| c.collection_name == collection }
end

#collection(name, &block) ⇒ Object

Create DSL wrapper for creating a new collection

Example:

collection :images do
  description "Images collection"

  operation :index do
    ...
  end
end


32
33
34
35
36
37
38
39
40
41
# File 'lib/sinatra/rabbit/dsl.rb', line 32

def collection(name, &block)
  return self[name] unless block_given?
  current_collection = BaseCollection.collection_class(name) do |c|
    c.base_class = self
    c.generate(name, &block)
  end
  collections << current_collection
  DSL << current_collection
  use current_collection
end

#collectionsObject

Return all defined collections



45
46
47
# File 'lib/sinatra/rabbit/dsl.rb', line 45

def collections
  @collections ||= []
end