Module: Sinatra::Rabbit

Defined in:
lib/sinatra/rabbit/dsl.rb,
lib/sinatra/rabbit/base.rb,
lib/sinatra/rabbit/param.rb,
lib/sinatra/rabbit/features.rb,
lib/sinatra/rabbit/validator.rb,
lib/sinatra/rabbit/base_collection.rb

Defined Under Namespace

Modules: DSL, Features, Validator Classes: BaseCollection, Collection, Feature, Param

Constant Summary

STANDARD_OPERATIONS =
{
  :create => {
    :member => false,
    :method => :post,
    :collection => true
  },
  :show => {
    :member => false,
    :method => :get,
    :required_params => [ :id ]
  },
  :destroy => {
    :member => false,
    :method => :delete,
    :required_params => [ :id ]
  },
  :index => {
    :member => false,
    :method => :get,
    :collection => true
  },
  :update => {
    :member => false,
    :method => :patch,
    :required_params => [ :id ] 
  }
}

Class Method Summary (collapse)

Class Method Details

+ (Object) configuration



59
60
61
# File 'lib/sinatra/rabbit/base.rb', line 59

def self.configuration
  Thread.current[:rabbit_configuration] ||= {}
end

+ (Object) configure(&block)



55
56
57
# File 'lib/sinatra/rabbit/base.rb', line 55

def self.configure(&block)
  instance_eval(&block)
end

+ (Object) disable(property)



75
76
77
# File 'lib/sinatra/rabbit/base.rb', line 75

def self.disable(property)
  configuration[property] = false
end

+ (Boolean) disabled?(property)



71
72
73
# File 'lib/sinatra/rabbit/base.rb', line 71

def self.disabled?(property)
  !configuration[property].nil? and configuration[property] == false
end

+ (Object) enable(property)



63
64
65
# File 'lib/sinatra/rabbit/base.rb', line 63

def self.enable(property)
  configuration[property] = true
end

+ (Boolean) enabled?(property)



67
68
69
# File 'lib/sinatra/rabbit/base.rb', line 67

def self.enabled?(property)
  !configuration[property].nil? and configuration[property] == true
end

+ (Object) included(base)

Automatically register the DSL to Sinatra::Base if this module is included:

Example:

class MyApp << Sinatra::Base
  include Sinatra::Rabbit
end


93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/sinatra/rabbit/base.rb', line 93

def self.included(base)
  configuration[:root_path] ||= '/'
  base.register(Rabbit::DSL) if base.respond_to? :register
  if configuration[:use_namespace]
    configuration[:base_module] = const_get(base.name.split('::').first)
  end
  base.get '/docs' do
    css_file = File.read(File.join(File.dirname(__FILE__), '..', 'docs', 'bootstrap.min.css'))
    index_file = File.read(File.join(File.dirname(__FILE__), '..', 'docs', 'api.haml'))
    haml index_file, :locals => { :base => base.respond_to?(:documentation_class) ? base.documentation_class : base, :css => css_file }
  end
end

+ (Object) set(property, value)



79
80
81
# File 'lib/sinatra/rabbit/base.rb', line 79

def self.set(property, value)
  configuration[property] = value
end