Class: Sinatra::Default

Inherits:
Base
  • Object
show all
Defined in:
lib/sinatra/base.rb,
lib/sinatra/main.rb,
lib/sinatra/compat.rb

Overview

Base class for classic style (top-level) applications.

Direct Known Subclasses

Application

Defined Under Namespace

Classes: Options

Instance Attribute Summary

Attributes inherited from Base

#app, #env, #params, #request, #response

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

before, #call, call, #call!, condition, configure, delete, development?, disable, enable, error, #forward, get, #halt, head, helpers, #initialize, layout, media_type, new, not_found, #pass, post, production?, prototype, put, reload!, reloading?, reset!, run!, set, template, test?, use, use_in_file_templates!

Methods included from Templates

#builder, #erb, #haml, #sass

Methods included from Helpers

#attachment, #back, #body, #content_type, #error, #etag, #last_modified, #media_type, #not_found, #redirect, #send_file, #session, #status

Constructor Details

This class inherits a constructor from Sinatra::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &b) ⇒ Object

Deprecated. Missing messages are no longer delegated to @response.



200
201
202
203
204
205
206
207
# File 'lib/sinatra/compat.rb', line 200

def method_missing(name, *args, &b) #:nodoc:
  if @response.respond_to?(name)
    sinatra_warn "The '#{name}' method is deprecated; use 'response.#{name}' instead."
    @response.send(name, *args, &b)
  else
    super
  end
end

Class Method Details

.configures(*args, &block) ⇒ Object

Deprecated. Use: configure



162
163
164
165
# File 'lib/sinatra/compat.rb', line 162

def configures(*args, &block)
  sinatra_warn "The 'configures' method is deprecated; use 'configure' instead."
  configure(*args, &block)
end

.const_missing(const_name) ⇒ Object

:nodoc:



78
79
80
81
82
83
84
85
86
87
# File 'lib/sinatra/compat.rb', line 78

def self.const_missing(const_name) #:nodoc:
  if const_name == :FORWARD_METHODS
    sinatra_warn 'Sinatra::Application::FORWARD_METHODS is deprecated;',
      'use Sinatra::Delegator::METHODS instead.'
    const_set :FORWARD_METHODS, Sinatra::Delegator::METHODS
    Sinatra::Delegator::METHODS
  else
    super
  end
end

.default_optionsObject

Deprecated. Use: set



168
169
170
171
172
173
# File 'lib/sinatra/compat.rb', line 168

def default_options
  sinatra_warn "Sinatra::Application.default_options is deprecated; use 'set' instead."
  fake = lambda { |options| set(options) }
  def fake.merge!(options) ; call(options) ; end
  fake
end

.envObject

Deprecated. Use: options.environment



193
194
195
196
# File 'lib/sinatra/compat.rb', line 193

def env
  sinatra_warn "The :env option is deprecated; use :environment instead."
  environment
end

.env=(value) ⇒ Object

Deprecated. Use: set :environment, ENV



187
188
189
190
# File 'lib/sinatra/compat.rb', line 187

def env=(value)
  sinatra_warn "The :env option is deprecated; use :environment instead."
  set :environment, value
end

.optionsObject

Deprecated. Options are stored directly on the class object.



156
157
158
159
# File 'lib/sinatra/compat.rb', line 156

def options
  sinatra_warn "The 'options' class method is deprecated; use 'self' instead."
  Options.new(self)
end

.register(*extensions, &block) ⇒ Object

:nodoc:



963
964
965
966
967
# File 'lib/sinatra/base.rb', line 963

def self.register(*extensions, &block) #:nodoc:
  added_methods = extensions.map {|m| m.public_instance_methods }.flatten
  Delegator.delegate *added_methods
  super(*extensions, &block)
end

.set_option(*args, &block) ⇒ Object

Deprecated. Use: set



176
177
178
179
# File 'lib/sinatra/compat.rb', line 176

def set_option(*args, &block)
  sinatra_warn "The 'set_option' method is deprecated; use 'set' instead."
  set(*args, &block)
end

.set_options(*args, &block) ⇒ Object



181
182
183
184
# File 'lib/sinatra/compat.rb', line 181

def set_options(*args, &block)
  sinatra_warn "The 'set_options' method is deprecated; use 'set' instead."
  set(*args, &block)
end

Instance Method Details

#entity_tag(*args, &block) ⇒ Object

Deprecated. Use: etag



104
105
106
107
# File 'lib/sinatra/compat.rb', line 104

def entity_tag(*args, &block)
  sinatra_warn "The 'entity_tag' method is deprecated; use 'etag' instead."
  etag(*args, &block)
end

#headers(header = nil) ⇒ Object Also known as: header

Deprecated. Use: response



90
91
92
93
94
# File 'lib/sinatra/compat.rb', line 90

def headers(header=nil)
  sinatra_warn "The 'headers' method is deprecated; use 'response' instead."
  response.headers.merge!(header) if header
  response.headers
end

#invoke(&block) ⇒ Object

Throwing halt with a Symbol and the to_result convention are deprecated. Override the invoke method to detect those types of return values.



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/sinatra/compat.rb', line 123

def invoke(&block) #:nodoc:
  res = super
  case
  when res.kind_of?(Symbol)
    sinatra_warn "Invoking the :#{res} helper by returning a Symbol is deprecated;",
      "call the helper directly instead."
    @response.body = __send__(res)
  when res.respond_to?(:to_result)
    sinatra_warn "The to_result convention is deprecated."
    @response.body = res.to_result(self)
  end
  res
end

#optionsObject

:nodoc:



137
138
139
# File 'lib/sinatra/compat.rb', line 137

def options #:nodoc:
  Options.new(self.class)
end

#send_data(data, options = {}) ⇒ Object

Deprecated. Use the #attachment helper and return the data as a String or Array.



111
112
113
114
115
116
117
118
# File 'lib/sinatra/compat.rb', line 111

def send_data(data, options={})
  sinatra_warn "The 'send_data' method is deprecated. use attachment, status, content_type, etc. helpers instead."

  status       options[:status]   if options[:status]
  attachment   options[:filename] if options[:disposition] == 'attachment'
  content_type options[:type]     if options[:type]
  halt data
end

#stop(*args, &block) ⇒ Object

Deprecated. Use: halt



98
99
100
101
# File 'lib/sinatra/compat.rb', line 98

def stop(*args, &block)
  sinatra_warn "The 'stop' method is deprecated; use 'halt' instead."
  halt(*args, &block)
end