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 collapse

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

.configurationObject



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

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

.configure(&block) ⇒ Object



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

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

.disable(property) ⇒ Object



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

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

.disabled?(property) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.enable(property) ⇒ Object



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

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

.enabled?(property) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.included(base) ⇒ Object

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

.set(property, value) ⇒ Object



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

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