Module: Sinatra::Reloader::BaseMethods

Defined in:
lib/sinatra/reloader.rb

Overview

Contains the methods defined in Sinatra::Base that are overriden.

Instance Method Summary collapse

Instance Method Details

#add_filter(type, path = nil, options = {}, &block) ⇒ Object

Does everything Sinatra::Base#add_filter does, but it also tells the Watcher::List for the Sinatra application to watch the defined filter.



283
284
285
286
287
288
289
# File 'lib/sinatra/reloader.rb', line 283

def add_filter(type, path = nil, options = {}, &block)
  source_location = block.respond_to?(:source_location) ?
    block.source_location.first : caller_files[1]
  result = super
  watch_element(source_location, :"#{type}_filter", filters[type].last)
  result
end

#compile!(verb, path, block, options = {}) ⇒ Object

Does everything Sinatra::Base#route does, but it also tells the Watcher::List for the Sinatra application to watch the defined route.

Note: We are using #compile! so we don’t interfere with extensions changing #route.



250
251
252
253
254
255
256
257
258
# File 'lib/sinatra/reloader.rb', line 250

def compile!(verb, path, block, options = {})
  source_location = block.respond_to?(:source_location) ?
    block.source_location.first : caller_files[1]
  signature = super
  watch_element(
    source_location, :route, { :verb => verb, :signature => signature }
  )
  signature
end

#error(*codes, &block) ⇒ Object

Does everything Sinatra::Base#error does, but it also tells the Watcher::List for the Sinatra application to watch the defined error handler.



294
295
296
297
298
299
300
301
# File 'lib/sinatra/reloader.rb', line 294

def error(*codes, &block)
  path = caller_files[1] || File.expand_path($0)
  result = super
  codes.each do |c|
    watch_element(path, :error, :code => c, :handler => @errors[c])
  end
  result
end

#inherited(subclass) ⇒ Object

Does everything Sinatra::Base#register does and then registers the reloader in the subclass.



315
316
317
318
319
# File 'lib/sinatra/reloader.rb', line 315

def inherited(subclass)
  result = super
  subclass.register Sinatra::Reloader
  result
end

#inline_templates=(file = nil) ⇒ Object

Does everything Sinatra::Base#inline_templates= does, but it also tells the Watcher::List for the Sinatra application to watch the inline templates in file or the file who made the call to this method.



264
265
266
267
268
269
# File 'lib/sinatra/reloader.rb', line 264

def inline_templates=(file=nil)
  file = (file.nil? || file == true) ?
    (caller_files[1] || File.expand_path($0)) : file
  watch_element(file, :inline_templates)
  super
end

#register(*extensions, &block) ⇒ Object

Does everything Sinatra::Base#register does, but it also lets the reloader know that an extension is being registered, because the elements defined in its registered method need a special treatment.



306
307
308
309
310
311
# File 'lib/sinatra/reloader.rb', line 306

def register(*extensions, &block)
  start_registering_extension
  result = super
  stop_registering_extension
  result
end

#run!(*args) ⇒ Object

Protects Sinatra::Base.run! from being called more than once.



236
237
238
239
240
241
242
# File 'lib/sinatra/reloader.rb', line 236

def run!(*args)
  if settings.reloader?
    super unless running?
  else
    super
  end
end

#use(middleware, *args, &block) ⇒ Object

Does everything Sinatra::Base#use does, but it also tells the Watcher::List for the Sinatra application to watch the middleware being used.



274
275
276
277
278
# File 'lib/sinatra/reloader.rb', line 274

def use(middleware, *args, &block)
  path = caller_files[1] || File.expand_path($0)
  watch_element(path, :middleware, [middleware, args, block])
  super
end