Permalink
Browse files

cleanup

  • Loading branch information...
1 parent a50c757 commit d4645b89f97942b9dcd4b1d726bd26dd6b93015d @rkh committed Oct 28, 2011
Showing with 1 addition and 320 deletions.
  1. +0 −27 LICENSE
  2. +1 −52 README.md
  3. +0 −124 lib/sinatra/reloader.rb
  4. +0 −24 sinatra-reloader.gemspec
  5. +0 −89 spec/sinatra/reloader_spec.rb
  6. +0 −4 spec/spec_helper.rb
View
27 LICENSE
@@ -1,27 +0,0 @@
-copyright (c) 2010 Konstantin Haase. All rights reserved.
-
-Developed by: Konstantin Haase
- http://github.com/rkh/big_band
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to
-deal with the Software without restriction, including without limitation the
-rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
-sell copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
- 1. Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimers.
- 2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimers in the
- documentation and/or other materials provided with the distribution.
- 3. Neither the name of Konstantin Haase, nor the names of other contributors
- may be used to endorse or promote products derived from this Software without
- specific prior written permission.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-WITH THE SOFTWARE.
View
53 README.md
@@ -1,52 +1 @@
-Sinatra::Reloader
-=================
-
-Advanced code reloader for [Sinatra](http://sinatrarb.com). Reloads only files that have
-changed and automatically detects orphaned routes that have to be removed. Most other
-implementations delete all routes and reload all code if one file changed, which takes way
-more time than reloading only one file, especially in larger projects. Files defining
-routes will be added to the reload list per default. Avoid reloading with dont_reload. Add
-other files to the reload list with also_reload.
-
-BigBand
--------
-
-Sinatra::Reloader is part of the [BigBand](http://github.com/rkh/big_band) stack.
-Check it out if you are looking for other fancy Sinatra extensions.
-
-BigBand will setup the reloader automatically, but only in development mode.
-
-Installation
-------------
-
- gem install sinatra-reloader
-
-Usage
------
-
-Simple usage:
-
- require "sinatra"
- require "sinatra/reloader" if development?
-
-More complex:
-
- require "sinatra"
-
- configure(:development) do |c|
- require "sinatra/reloader"
- c.also_reload "*.rb"
- end
-
-Modular:
-
- require "sinatra/base"
- require "sinatra/reloader"
-
- class Foo < Sinatra::Base
- configure(:development) do
- register Sinatra::Reloader
- also_reload "app/models/*.rb"
- dont_reload "lib/**/*.rb"
- end
- end
+This project is now part of [sinatra-contrib](https://github.com/sinatra/sinatra-contrib/).
View
124 lib/sinatra/reloader.rb
@@ -1,124 +0,0 @@
-require "monkey-lib"
-require "sinatra/base"
-require "sinatra/sugar"
-require "sinatra/advanced_routes"
-
-module Sinatra
- Base.ignore_caller
-
- module Reloader
- class FileWatcher < Array
- attr_reader :file, :mtime, :inline_templates, :app
- extend Enumerable
- @map ||= {}
-
- def self.register(route)
- new(route.file, route.app) << route if route.file?
- end
-
- def self.new(file, app)
- file = file.expand_path
- begin
- file = file.realpath
- rescue Errno::ENOENT
- end
- @map[file] ||= super
- end
-
- class << self
- alias [] new
- end
-
- def self.each(&block)
- @map.values.each(&block)
- end
-
- def initialize(file, app)
- @reload, @file, @app = true, file, app
- @mtime = File.exist?(file) ? File.mtime(file) : Time.at(0)
- super()
- end
-
- def changed?
- !File.exist? file or @mtime != File.mtime(file)
- end
-
- def dont_reload!(dont = true)
- @reload = !dont
- end
-
- def reload?
- @reload and changed?
- end
-
- def reload
- reload! if reload?
- end
-
- def inline_templates?
- !!inline_templates
- end
-
- def inline_templates!
- @inline_templates = true
- end
-
- def reload!
- each { |route| route.deactivate }
- $LOADED_FEATURES.delete file
- clear
- if File.exist? file
- app.set :inline_templates, file if inline_templates?
- @mtime = File.mtime(file)
- require file
- end
- end
- end
-
- module ClassMethods
- def dont_reload(*files)
- if [true, false].include? files.last then dont = files.pop
- else dont = true
- end
- files.flatten.each do |file|
- # Rubinius and JRuby ignore block passed to glob.
- Dir.glob(file).each { |f| FileWatcher[f, self].dont_reload! dont }
- FileWatcher[file, self].dont_reload! dont
- end
- end
-
- def also_reload(*files)
- dont_reload(files, false)
- end
-
- def inline_templates=(file = nil)
- file = (file.nil? || file == true) ? caller_files.first : (file || $0)
- FileWatcher[file, self].inline_templates!
- super
- end
- end
-
- def self.registered(klass)
- klass.register AdvancedRoutes
- klass.extend ClassMethods
- klass.each_route { |route| advanced_route_added(route) }
- klass.enable :reload_templates
- klass.before { Reloader.reload_routes }
- end
-
- def self.advanced_route_added(route)
- FileWatcher.register(route)
- end
-
- def self.thread_safe?
- Thread and Thread.list.size > 1 and Thread.respond_to? :exclusive
- end
-
- def self.reload_routes(thread_safe = true)
- return Thread.exclusive { reload_routes(false) } if thread_safe and thread_safe?
- FileWatcher.each { |file| file.reload }
- end
- end
-
- register Reloader
-end
View
24 sinatra-reloader.gemspec
@@ -1,24 +0,0 @@
-SPEC = Gem::Specification.new do |s|
-
- # Get the facts.
- s.name = "sinatra-reloader"
- s.version = "0.5.0"
- s.description = "Smart and fast code reloader for Sinatra (part of BigBand)."
-
- # BigBand depedencies
- s.add_dependency "sinatra-advanced-routes", "~> 0.5.0"
- s.add_development_dependency "sinatra-test-helper", "~> 0.5.0"
-
- # External dependencies
- s.add_dependency "sinatra", "~> 1.0"
- s.add_development_dependency "rspec", ">= 1.3.0"
-
- # Those should be about the same in any BigBand extension.
- s.authors = ["Konstantin Haase"]
- s.email = "konstantin.mailinglists@googlemail.com"
- s.files = Dir["**/*.{rb,md}"] << "LICENSE"
- s.homepage = "http://github.com/rkh/#{s.name}"
- s.require_paths = ["lib"]
- s.summary = s.description
-
-end
View
89 spec/sinatra/reloader_spec.rb
@@ -1,89 +0,0 @@
-require File.expand_path("../../spec_helper", __FILE__)
-
-describe Sinatra::Reloader do
- it_should_behave_like 'sinatra'
-
- def app_file(file, content)
- file = File.expand_path(file, @temp_dir)
- old_mtime = File.exist?(file) ? File.mtime(file) : Time.at(0)
- new_mtime = old_mtime
- # this is eventually faster than a hard coded sleep 1, also it adjusts to the systems
- # mtime granularity
- until new_mtime > old_mtime
- File.open(file, "w") do |f|
- f << "class ::ExampleApp < Sinatra::Base; #{content}; end\n"
- yield f if block_given?
- end
- File.utime File.atime(file), old_mtime + 10, file unless ENV['MTIME']
- new_mtime = File.mtime file
- # ok, let's not generate too much io
- sleep 0.1 if new_mtime == old_mtime
- end
- require file
- file
- end
-
- def app
- ::ExampleApp
- end
-
- before do
- @temp_dir ||= File.expand_path "../../temp", __FILE__
- rm_rf @temp_dir
- mkdir_p @temp_dir
- $LOADED_FEATURES.reject! { |f| f =~ /^#{@temp_dir}/ }
- class ::ExampleApp < Sinatra::Base
- reset!
- register Sinatra::Reloader
- end
- end
-
- after :all do
- rm_rf @temp_dir
- end
-
- it "should reload files" do
- app_file("example_app.rb", "get('/foo') { 'foo' }")
- browse_route(:get, '/foo').body.should == 'foo'
- app_file("example_app.rb", "get('/foo') { 'bar' }")
- browse_route(:get, '/foo').body.should == 'bar'
- end
-
- it "should not affact other routes" do
- app_file("example_app.rb", "get('/foo') { 'foo' }")
- app_file("example_app2.rb", "get('/bar') { 'bar' }")
- browse_route(:get, '/bar').body.should == 'bar'
- app_file("example_app.rb", "get('/foo') { 'bar' }")
- browse_route(:get, '/bar').body.should == 'bar'
- end
-
- it "should respect dont_reload" do
- file = app_file("example_app3.rb", "get('/baz') { 'foo' }")
- app.dont_reload file
- app_file("example_app3.rb", "get('/baz') { 'bar' }")
- browse_route(:get, '/baz').body.should == 'foo'
- end
-
- it "reloads inline templates" do
- file = app_file("example_app4.rb", "get('/foo') { haml :foo }") { |f| f.puts "__END__", "@@foo", "foo" }
- app.set :inline_templates, file
- browse_route(:get, '/foo').body.strip.should == "foo"
- app_file("example_app4.rb", "get('/foo') { haml :foo }") { |f| f.puts "__END__", "@@foo", "bar" }
- browse_route(:get, '/foo').body.strip.should == "bar"
- end
-
- it "should not readd middleware" do
- 3.times do
- app_file "example_app5.rb", <<-RUBY
- use Rack::Config do |env|
- env['some.counter'] ||= 0
- env['some.counter'] += 1
- $counter = env['some.counter']
- end
- RUBY
- browse_route :get, '/foo'
- end
- $counter.should == 1
- end
-
-end
View
4 spec/spec_helper.rb
@@ -1,4 +0,0 @@
-require "sinatra/rspec/shared"
-require "sinatra/reloader"
-require "fileutils"
-include FileUtils

0 comments on commit d4645b8

Please sign in to comment.