Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making config/config.json customizable through config.rb #15

Merged
merged 3 commits into from
Mar 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ Dash class, and hence, all Sinatra configuration.

``` ruby
set :port, 6000 # HTTP server on port 6000
config[:ws_config] = 'custom/config.json' # Specify custom workspace config
```
14 changes: 10 additions & 4 deletions example/config.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
# Serve HTTP traffic on this port
set :port, 5000
set :port, 4567

riemann_base = '.'
riemann_src = "${riemann_base}/lib/riemann/dash"

# Add custom controllers in controller/
config[:controllers] << 'controller'
config[:controllers] = ["#{riemann_src}/controller"]

# Use the local view directory instead of the default
config[:views] = 'views'
config[:views] = "#{riemann_src}/views"

# Specify a custom path to your workspace config.json
config[:ws_config] = "#{riemann_base}/config/config.json"

# Serve static files from this directory
public_dir 'public'
config[:public] = "#{riemann_src}/public"
12 changes: 9 additions & 3 deletions lib/riemann/dash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class Dash < Sinatra::Base
def self.config
@config ||= {
:controllers => [File.join(File.dirname(__FILE__), 'dash', 'controller')],
:views => File.join(File.dirname(__FILE__), 'dash', 'views')
:views => File.join(File.dirname(__FILE__), 'dash', 'views'),
:ws_config => File.join(File.dirname(__FILE__), '..', '..', 'config', 'config.json'),
:public => File.join(File.dirname(__FILE__), 'dash', 'public')
}
end

Expand All @@ -23,11 +25,14 @@ def self.load(filename)
puts "No configuration loaded; using defaults."
end

# load controllers
config[:controllers].each { |d| load_controllers d }

# views
set :views, File.expand_path(config[:views])

# Fallback pub dir
public_dir(File.join(File.dirname(__FILE__), 'dash', 'public'))
# setup public dir
public_dir(config[:public])
end

# Executes the configuration file.
Expand Down Expand Up @@ -96,4 +101,5 @@ def self.public_dir(dir)
use Riemann::Dash::Static, :root => dir
end
end

end
2 changes: 1 addition & 1 deletion lib/riemann/dash/controller/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class Riemann::Dash
require 'fileutils'
require 'set'

WS_CONFIG_FILE = "config/config.json"
WS_CONFIG_FILE = @config[:ws_config]

get '/' do
erb :index, :layout => false
Expand Down