Module: Sinatra::SinareyReloader::BaseMethods

Defined in:
lib/sinatra/sinarey_reloader.rb

Instance Method Summary collapse

Instance Method Details

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



160
161
162
163
164
165
166
# File 'lib/sinatra/sinarey_reloader.rb', line 160

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



127
128
129
130
131
132
133
134
135
# File 'lib/sinatra/sinarey_reloader.rb', line 127

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



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

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



184
185
186
187
188
# File 'lib/sinatra/sinarey_reloader.rb', line 184

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

#inline_templates=(file = nil) ⇒ Object



147
148
149
150
151
152
# File 'lib/sinatra/sinarey_reloader.rb', line 147

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



177
178
179
180
181
182
# File 'lib/sinatra/sinarey_reloader.rb', line 177

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

#run!(*args) ⇒ Object



119
120
121
122
123
124
125
# File 'lib/sinatra/sinarey_reloader.rb', line 119

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

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



137
138
139
140
141
142
143
144
145
# File 'lib/sinatra/sinarey_reloader.rb', line 137

def turbo_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, :turbo_route, { :verb => verb, :path => path, :block_id => signature }
  )
  signature
end

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



154
155
156
157
158
# File 'lib/sinatra/sinarey_reloader.rb', line 154

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