Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion lib/generators/private_pub/templates/private_pub.ru
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require "yaml"
require "faye"
require "private_pub"

Faye::WebSocket.load_adapter('thin')
Faye::WebSocket.load_adapter('puma')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's not related to this pull request :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. I was experimenting with puma rack hijacking. I'm surprised this is here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. My bad, I thought the pull request was for the commit when I submitted the pull request, not my branch's head.

On May 24, 2013, at 5:16 AM, Vasiliy Ermolovich [email protected] wrote:

In 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')
I think it's not related to this pull request :)


Reply to this email directly or view it on GitHub.


PrivatePub.load_config(File.expand_path("../config/private_pub.yml", __FILE__), ENV["RAILS_ENV"] || "development")
run PrivatePub.faye_app
4 changes: 3 additions & 1 deletion lib/private_pub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

require "private_pub/faye_extension"
require "private_pub/engine" if defined? Rails
require "yaml"

module PrivatePub
class Error < StandardError; end
Expand All @@ -18,9 +19,10 @@ 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 }
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
Expand Down
4 changes: 2 additions & 2 deletions private_pub.gemspec
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]"
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"
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/private_pub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions spec/private_pub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down