Skip to content

Commit

Permalink
Updated instructions for API reloading.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Jan 25, 2013
1 parent 3494a60 commit 371921f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Next Release
* [#309](https://github.com/intridea/grape/pull/309): An XML format API will return an error instead of returning a string representation of the response if the latter cannot be converted to XML - [@dblock](http://github.com/dblock).
* [#309](https://github.com/intridea/grape/pull/309): Added XML support to entities - [@johnnyiller](https://github.com/johnnyiller), [@dblock](http://github.com/dblock).
* A formatter that raises an exception will cause the API to return a 500 error - [@dblock](http://github.com/dblock).
* [#131](https://github.com/intridea/grape/issues/131) Fix README.markdown instructions regarding Rails 3.x reloading. Using instructions from Wiki works better - [@jyn](http://github.com/jyn)
* [#131](https://github.com/intridea/grape/issues/131) Added instructions for Grape API reloading in Rails - [@jyn](http://github.com/jyn), [@dblock](http://github.com/dblock).
* Your contribution here.

0.2.6 (01/11/2013)
Expand Down
22 changes: 12 additions & 10 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -1002,28 +1002,30 @@ end

### Rails 3.x

Source: http://stackoverflow.com/questions/3282655/ruby-on-rails-3-reload-lib-directory-for-each-request/4368838#4368838
Add API paths to `config/application.rb`.

Create file `config/initializers/reload_lib.rb`
```ruby
# Auto-load API and its subdirectories
config.paths.add "app/api", :glob => "**/*.rb"
config.autoload_paths += Dir["#{Rails.root}/app/api/*"]
```

Create `config/initializers/reload_api.rb`.

```ruby
if Rails.env.development?
lib_reloader = ActiveSupport::FileUpdateChecker.new(Dir["app/api/**/*"]) do
api_files = Dir["#{Rails.root}/app/api/**/*.rb"]
api_reloader = ActiveSupport::FileUpdateChecker.new(api_files) do
Rails.application.reload_routes!
end

ActionDispatch::Callbacks.to_prepare do
lib_reloader.execute_if_updated
api_reloader.execute_if_updated
end
end
```

In `config/application.rb`, add
See [StackOverflow #3282655](http://stackoverflow.com/questions/3282655/ruby-on-rails-3-reload-lib-directory-for-each-request/4368838#4368838) for more information.

```ruby
config.autoload_paths += %W(#{config.root}/app/api)
config.autoload_paths += Dir["#{config.root}/app/api/**/"]
```

## Performance Monitoring

Expand Down

0 comments on commit 371921f

Please sign in to comment.