From 3c98ee3066ced342beb392d25e28d2e862ddf1c1 Mon Sep 17 00:00:00 2001 From: Dave Gerton Date: Mon, 22 Apr 2013 15:50:38 -1000 Subject: [PATCH 1/6] Allow ERB tags in configuration file --- lib/private_pub.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private_pub.rb b/lib/private_pub.rb index a595cf8..76b2dc6 100644 --- a/lib/private_pub.rb +++ b/lib/private_pub.rb @@ -18,7 +18,7 @@ def reset_config # Loads the configuration from a given YAML file and environment (such as production) def load_config(filename, environment) - yaml = YAML.load_file(filename)[environment.to_s] + yaml = YAML.load(ERB.new(File.read(filename)).result)[environment.to_s] raise ArgumentError, "The #{environment} environment does not exist in #{filename}" if yaml.nil? yaml.each { |k, v| config[k.to_sym] = v } end From a599fc1d7d82e68d844a933b394f00f9e326e993 Mon Sep 17 00:00:00 2001 From: Dave Gerton Date: Mon, 22 Apr 2013 16:35:40 -1000 Subject: [PATCH 2/6] Force signature_expiration to an integer, add tests --- lib/private_pub.rb | 2 ++ spec/fixtures/private_pub.yml | 4 ++++ spec/private_pub_spec.rb | 10 ++++++++++ 3 files changed, 16 insertions(+) diff --git a/lib/private_pub.rb b/lib/private_pub.rb index 76b2dc6..8fc4f7f 100644 --- a/lib/private_pub.rb +++ b/lib/private_pub.rb @@ -4,6 +4,7 @@ require "private_pub/faye_extension" require "private_pub/engine" if defined? Rails +require "yaml" module PrivatePub class Error < StandardError; end @@ -21,6 +22,7 @@ def load_config(filename, environment) yaml = YAML.load(ERB.new(File.read(filename)).result)[environment.to_s] raise ArgumentError, "The #{environment} environment does not exist in #{filename}" if yaml.nil? yaml.each { |k, v| config[k.to_sym] = v } + config[:signature_expiration] = config[:signature_expiration].to_i if config[:signature_expiration] && !config[:signature_expiration].is_a?(Integer) end # Publish the given data to a specific channel. This ends up sending diff --git a/spec/fixtures/private_pub.yml b/spec/fixtures/private_pub.yml index 57eb4d3..04f468d 100644 --- a/spec/fixtures/private_pub.yml +++ b/spec/fixtures/private_pub.yml @@ -2,6 +2,10 @@ development: server: http://dev.local:9292/faye secret_token: DEVELOPMENT_SECRET_TOKEN signature_expiration: 600 +staging: + server: <%= ENV['FAYE_SERVER'] %> + secret_token: <%= ENV['FAYE_TOKEN'] %> + signature_expiration: <%= ENV['FAYE_EXPIRATION'] %> production: server: http://example.com/faye secret_token: PRODUCTION_SECRET_TOKEN diff --git a/spec/private_pub_spec.rb b/spec/private_pub_spec.rb index 3929009..644a4db 100644 --- a/spec/private_pub_spec.rb +++ b/spec/private_pub_spec.rb @@ -26,6 +26,16 @@ PrivatePub.config[:signature_expiration].should eq(600) end + it "loads a configuration file with erb tags via load_config" do + ENV["FAYE_SERVER"] = "http://example.com/faye" + ENV["FAYE_TOKEN"] = "STAGING_SECRET_TOKEN" + ENV["FAYE_EXPIRATION"] = "600" + PrivatePub.load_config("spec/fixtures/private_pub.yml", "staging") + PrivatePub.config[:server].should eq("http://example.com/faye") + PrivatePub.config[:secret_token].should eq("STAGING_SECRET_TOKEN") + PrivatePub.config[:signature_expiration].should eq(600) + end + it "raises an exception if an invalid environment is passed to load_config" do lambda { PrivatePub.load_config("spec/fixtures/private_pub.yml", :test) From 94011b94e2566c8ace82cdc3213cdf30ba823df6 Mon Sep 17 00:00:00 2001 From: Dave Gerton Date: Mon, 13 May 2013 11:15:25 -1000 Subject: [PATCH 3/6] Change adapter to puma --- lib/generators/private_pub/templates/private_pub.ru | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/private_pub/templates/private_pub.ru b/lib/generators/private_pub/templates/private_pub.ru index 4892af4..a1c80c1 100644 --- a/lib/generators/private_pub/templates/private_pub.ru +++ b/lib/generators/private_pub/templates/private_pub.ru @@ -4,7 +4,7 @@ require "yaml" require "faye" require "private_pub" -Faye::WebSocket.load_adapter('thin') +Faye::WebSocket.load_adapter('puma') PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development") run PrivatePub.faye_app From 54187bfd1c9fbcdc03224813ad595067e00dd482 Mon Sep 17 00:00:00 2001 From: Dave Gerton Date: Mon, 13 May 2013 11:18:05 -1000 Subject: [PATCH 4/6] Change description and bump version --- private_pub.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/private_pub.gemspec b/private_pub.gemspec index 5c0b872..64deabb 100644 --- a/private_pub.gemspec +++ b/private_pub.gemspec @@ -1,11 +1,11 @@ Gem::Specification.new do |s| s.name = "private_pub" - s.version = "1.0.3" + s.version = "1.0.4" s.author = "Ryan Bates" s.email = "ryan@railscasts.com" s.homepage = "http://github.com/ryanb/private_pub" s.summary = "Private pub/sub messaging in Rails." - s.description = "Private pub/sub messaging in Rails through Faye." + s.description = "Private pub/sub messaging in Rails through Faye with command env params and puma." s.files = Dir["{app,lib,spec}/**/*", "[A-Z]*", "init.rb"] - ["Gemfile.lock"] s.require_path = "lib" From 53a4e1138bf93ee21a2f9c53491a667a51c8d259 Mon Sep 17 00:00:00 2001 From: Dave Gerton Date: Tue, 28 May 2013 10:14:19 -1000 Subject: [PATCH 5/6] Reverting to thin --- lib/generators/private_pub/templates/private_pub.ru | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generators/private_pub/templates/private_pub.ru b/lib/generators/private_pub/templates/private_pub.ru index a1c80c1..4892af4 100644 --- a/lib/generators/private_pub/templates/private_pub.ru +++ b/lib/generators/private_pub/templates/private_pub.ru @@ -4,7 +4,7 @@ require "yaml" require "faye" require "private_pub" -Faye::WebSocket.load_adapter('puma') +Faye::WebSocket.load_adapter('thin') PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development") run PrivatePub.faye_app From 3703d0acd08d39fa0b9a7969668168f24e8c15c3 Mon Sep 17 00:00:00 2001 From: Dave Gerton Date: Tue, 28 May 2013 10:16:41 -1000 Subject: [PATCH 6/6] Update private_pub.gemspec --- private_pub.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/private_pub.gemspec b/private_pub.gemspec index 64deabb..a7ede7d 100644 --- a/private_pub.gemspec +++ b/private_pub.gemspec @@ -5,7 +5,7 @@ Gem::Specification.new do |s| s.email = "ryan@railscasts.com" s.homepage = "http://github.com/ryanb/private_pub" s.summary = "Private pub/sub messaging in Rails." - s.description = "Private pub/sub messaging in Rails through Faye with command env params and puma." + s.description = "Private pub/sub messaging in Rails through Faye with command env params." s.files = Dir["{app,lib,spec}/**/*", "[A-Z]*", "init.rb"] - ["Gemfile.lock"] s.require_path = "lib"