Skip to main content
Code Review

Return to Question

edited tags; edited title
Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Refactor Rails middleware initialization block

Notice removed Draw attention by Community Bot
Bounty Ended with no winning answer by Community Bot
Notice added Draw attention by caffo
Bounty Started worth 100 reputation by caffo
Tweeted twitter.com/#!/StackCodeReview/status/318904213214199809
Source Link
caffo
  • 31
  • 6

Refactor Rails middleware initialization block

I'm working on a simple superfeedr powered rails app here.

Based on the superfeedr-rack gem documentation, I'm doing this to initialize the middleware (snippet from application.rb config block):

Configuration = YAML.load_file(Rails.root.join('config', 'config.yml'))
config.middleware.use Rack::Superfeedr, { :host => Configuration["general"]["hostname"], :login => Configuration["superfeedr"]["username"], :password => Configuration["superfeedr"]["password"]} do |superfeedr|
 Superfeedr = superfeedr
 superfeedr.on_notification do |notification|
 Article.create_from_raw_notification(notification)
 end
end

I'm looking for a better way to do it - I don't like to load my configuration file there instead of in an initializer and I think the block with the article creation callback smells. Any ideas?

lang-rb

AltStyle によって変換されたページ (->オリジナル) /