Skip to content

Instantly share code, notes, and snippets.

@nutrun
Created June 24, 2010 00:56

Revisions

  1. gmalamid revised this gist Jun 24, 2010. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions sinatra_reloader.rb
    Original file line number Diff line number Diff line change
    @@ -21,8 +21,8 @@ module Sinatra
    module Reloader
    def self.extended(target)
    target.before { target.reload }
    default_path = [File.expand_path(File.join(File.dirname(__FILE__), '**', '*.rb'))]
    target.set(:reload_paths, default_path)
    default_path = File.expand_path(File.join(File.dirname(__FILE__), '**', '*.rb'))
    target.set(:reload_paths, [default_path])
    end

    def reload
  2. gmalamid revised this gist Jun 24, 2010. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion sinatra_reloader.rb
    Original file line number Diff line number Diff line change
    @@ -14,12 +14,15 @@
    # end
    #
    # :reload_paths should be an array of path patterns where the
    # source code intended for reloading resides
    # source code intended for reloading resides.
    # If not set, default is '<sinatra_reloader_dir>/**/*.rb'

    module Sinatra
    module Reloader
    def self.extended(target)
    target.before { target.reload }
    default_path = [File.expand_path(File.join(File.dirname(__FILE__), '**', '*.rb'))]
    target.set(:reload_paths, default_path)
    end

    def reload
  3. gmalamid revised this gist Jun 24, 2010. 1 changed file with 5 additions and 9 deletions.
    14 changes: 5 additions & 9 deletions sinatra_reloader.rb
    Original file line number Diff line number Diff line change
    @@ -23,19 +23,15 @@ def self.extended(target)
    end

    def reload
    source_files = scan_reload_paths
    source_files = reload_paths.inject({}) do |paths, pattern|
    Dir[pattern].each { |path| paths[path] = File.mtime(path) }
    paths
    end
    return if source_files == @source_files
    @source_files = source_files
    routes.clear
    @source_files.keys.each { |path| load(path) }
    end

    def scan_reload_paths
    reload_paths.inject({}) do |paths, pattern|
    Dir[pattern].each { |path| paths[path] = File.mtime(path) }
    paths
    end
    end
    end
    end

    register Reloader
  4. gmalamid created this gist Jun 24, 2010.
    42 changes: 42 additions & 0 deletions sinatra_reloader.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    # For "Classic" style/top-level type of apps do something like:
    #
    # configure :development do
    # require File.join(File.dirname(__FILE__), 'sinatra_reloader')
    # set :reload_paths, [File.join(File.dirname(__FILE__), '**', '*.rb')]
    # end
    #
    # For "Modular" style/Sinatra::Base subclasses:
    #
    # configure :development do
    # require File.join(File.dirname(__FILE__), 'sinatra_reloader')
    # register Sinatra::Reloader
    # set :reload_paths, [File.join(File.dirname(__FILE__), '**', '*.rb')]
    # end
    #
    # :reload_paths should be an array of path patterns where the
    # source code intended for reloading resides

    module Sinatra
    module Reloader
    def self.extended(target)
    target.before { target.reload }
    end

    def reload
    source_files = scan_reload_paths
    return if source_files == @source_files
    @source_files = source_files
    routes.clear
    @source_files.keys.each { |path| load(path) }
    end

    def scan_reload_paths
    reload_paths.inject({}) do |paths, pattern|
    Dir[pattern].each { |path| paths[path] = File.mtime(path) }
    paths
    end
    end
    end

    register Reloader
    end