Class: Sinatra::Default

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

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

accept_mime_types, before, #call, #call!, condition, delete, development?, disable, enable, error, get, #halt, head, host_name, #initialize, layout, media_type, not_found, #pass, post, production?, put, run!, set, template, test?, use, use_in_file_templates!, user_agent

Methods included from Templates

#builder, #erb, #haml, #lookup_layout, #lookup_template, #render, #render_builder, #render_erb, #render_haml, #render_sass, #sass, #template_path

Methods included from Helpers

#attachment, #body, #content_type, #error, #etag, #last_modified, #media_type, #not_found, #redirect, #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.



187
188
189
190
191
192
193
194
# File 'lib/sinatra/compat.rb', line 187

def method_missing(name, *args, &b)
  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

.call(env) ⇒ Object



815
816
817
818
819
820
# File 'lib/sinatra/base.rb', line 815

def self.call(env)
  synchronize do
    reload! if reload?
    super
  end
end

.configure(*envs) ⇒ Object



811
812
813
# File 'lib/sinatra/base.rb', line 811

def self.configure(*envs)
  super unless reloading?
end

.configures(*args, &block) ⇒ Object

Deprecated. Use: configure



149
150
151
152
# File 'lib/sinatra/compat.rb', line 149

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

.const_missing(const_name) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/sinatra/compat.rb', line 65

def self.const_missing(const_name)
  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



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

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



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

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

.env=(value) ⇒ Object

Deprecated. Use: set :environment, ENV



174
175
176
177
# File 'lib/sinatra/compat.rb', line 174

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.



143
144
145
146
# File 'lib/sinatra/compat.rb', line 143

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

.reload!Object



822
823
824
825
826
827
828
# File 'lib/sinatra/base.rb', line 822

def self.reload!
  @reloading = true
  superclass.send :inherited, self
  $LOADED_FEATURES.delete("sinatra.rb")
  ::Kernel.load app_file
  @reloading = false
end

.reloading?Boolean

Returns:

  • (Boolean)


807
808
809
# File 'lib/sinatra/base.rb', line 807

def self.reloading?
  @reloading ||= false
end

.set_option(*args, &block) ⇒ Object

Deprecated. Use: set



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

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



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

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



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

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



77
78
79
80
81
# File 'lib/sinatra/compat.rb', line 77

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

#invoke(handler) ⇒ Object

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



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/sinatra/compat.rb', line 110

def invoke(handler)
  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



124
125
126
# File 'lib/sinatra/compat.rb', line 124

def options
  Options.new(self.class)
end

#send_file(path, opts = {}) ⇒ Object

The :disposition option is deprecated; use: #attachment. This method setting the Content-Transfer-Encoding header is deprecated. – TODO deprecation warning for :disposition argument.



100
101
102
103
104
105
# File 'lib/sinatra/compat.rb', line 100

def send_file(path, opts={})
  opts[:disposition] = 'attachment' if !opts.key?(:disposition)
  attachment opts[:filename] || path if opts[:filename] || opts[:disposition]
  response['Content-Transfer-Encoding'] = 'binary' if opts[:disposition]
  super(path, opts)
end

#stop(*args, &block) ⇒ Object

Deprecated. Use: halt



85
86
87
88
# File 'lib/sinatra/compat.rb', line 85

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