Class: Camping::Reloader

Class | Camping::Reloader
In: | lib/camping/reloader.rb
Parent: | Object

## The Camping Reloader

Camping apps are generally small and predictable. Many Camping apps are contained within a single file. Larger apps are split into a handful of other Ruby libraries within the same directory.

Since Camping apps (and their dependencies) are loaded with Ruby‘s require method, there is a record of them in $LOADED_FEATURES. Which leaves a perfect space for this class to manage auto-reloading an app if any of its immediate dependencies changes.

## Wrapping Your Apps

Since bin/camping and the Camping::Server class already use the Reloader, you probably don‘t need to hack it on your own. But, if you‘re rolling your own situation, here‘s how.

Rather than this:

      require 'yourapp'

Use this:

      require 'camping/reloader'
      reloader = Camping::Reloader.new('/path/to/yourapp.rb')
      blog = reloader.apps[:Blog]
      wiki = reloader.apps[:Wiki]

The `blog` and `wiki` objects will behave exactly like your Blog and Wiki, but they will update themselves if yourapp.rb changes.

You can also give Reloader more than one script.

### Methods

clear new on_reload reload! script update

### Attributes

apps | [R] |
scripts | [R] |

### Public Class methods

new(*scripts)

Creates the reloader, assigns a `script` to it and initially loads the application. Pass in the full path to the script, otherwise the script will be loaded relative to the current working directory.

### Public Instance methods

clear()

Removes all the scripts from the reloader.

on_reload(&blk)
reload!()

Simply calls reload! on all the Script objects.

script(app)

Returns the script which provided the given app.

update(*scripts)

Updates the reloader to only use the scripts provided:

      reloader.update("examples/blog.rb", "examples/wiki.rb")

[Validate]