Module: Sinatra::Rabbit::DSL
- Included in:
- Collection
- Defined in:
- lib/sinatra/rabbit/dsl.rb
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) [](collection)
-
- (Object) collection(name, &block)
Create DSL wrapper for creating a new collection.
-
- (Object) collections
Return all defined collections.
Class Method Details
+ (Object) <<(c)
54 55 56 |
# File 'lib/sinatra/rabbit/dsl.rb', line 54 def self.<<(c) register_collection(c) end |
+ (Object) register_collection(c, &block)
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
- (Object) [](collection)
58 59 60 |
# File 'lib/sinatra/rabbit/dsl.rb', line 58 def [](collection) collections.find { |c| c.collection_name == collection } end |
- (Object) collection(name, &block)
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 |
- (Object) collections
Return all defined collections
45 46 47 |
# File 'lib/sinatra/rabbit/dsl.rb', line 45 def collections @collections ||= [] end |