Skip to content

Commit 55c5f3f

Browse files
author
FeryJ
committed
merge PR ryanb#75
1 parent 7ad7761 commit 55c5f3f

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

lib/private_pub.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
require "private_pub/faye_extension"
66
require "private_pub/engine" if defined? Rails
7+
require "yaml"
78

89
module PrivatePub
910
class Error < StandardError; end
@@ -18,9 +19,10 @@ def reset_config
1819

1920
# Loads the configuration from a given YAML file and environment (such as production)
2021
def load_config(filename, environment)
21-
yaml = YAML.load_file(filename)[environment.to_s]
22+
yaml = YAML.load(ERB.new(File.read(filename)).result)[environment.to_s]
2223
raise ArgumentError, "The #{environment} environment does not exist in #{filename}" if yaml.nil?
2324
yaml.each { |k, v| config[k.to_sym] = v }
25+
config[:signature_expiration] = config[:signature_expiration].to_i if config[:signature_expiration] && !config[:signature_expiration].is_a?(Integer)
2426
end
2527

2628
# Publish the given data to a specific channel. This ends up sending

private_pub.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
Gem::Specification.new do |s|
22
s.name = "private_pub"
3-
s.version = "1.0.3"
3+
s.version = "1.0.4"
44
s.author = "Ryan Bates"
55
s.email = "[email protected]"
66
s.homepage = "http://github.com/ryanb/private_pub"
77
s.summary = "Private pub/sub messaging in Rails."
8-
s.description = "Private pub/sub messaging in Rails through Faye."
8+
s.description = "Private pub/sub messaging in Rails through Faye with command env params (from PR #75)."
99

1010
s.files = Dir["{app,lib,spec}/**/*", "[A-Z]*", "init.rb"] - ["Gemfile.lock"]
1111
s.require_path = "lib"

spec/fixtures/private_pub.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ production:
66
server: http://example.com/faye
77
secret_token: PRODUCTION_SECRET_TOKEN
88
signature_expiration: 600
9+
staging:
10+
server: <%= ENV['FAYE_SERVER'] %>
11+
secret_token: <%= ENV['FAYE_TOKEN'] %>
12+
signature_expiration: <%= ENV['FAYE_EXPIRATION'] %>

spec/private_pub_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@
2626
PrivatePub.config[:signature_expiration].should eq(600)
2727
end
2828

29+
it "loads a configuration file with erb tags via load_config" do
30+
ENV["FAYE_SERVER"] = "http://example.com/faye"
31+
ENV["FAYE_TOKEN"] = "STAGING_SECRET_TOKEN"
32+
ENV["FAYE_EXPIRATION"] = "600"
33+
PrivatePub.load_config("spec/fixtures/private_pub.yml", "staging")
34+
PrivatePub.config[:server].should eq("http://example.com/faye")
35+
PrivatePub.config[:secret_token].should eq("STAGING_SECRET_TOKEN")
36+
PrivatePub.config[:signature_expiration].should eq(600)
37+
end
38+
2939
it "raises an exception if an invalid environment is passed to load_config" do
3040
lambda {
3141
PrivatePub.load_config("spec/fixtures/private_pub.yml", :test)

0 commit comments

Comments
 (0)