Permalink
Browse files

Move storage into configuration

  • Loading branch information...
1 parent 80e65bb commit 595c91587b963abd74fe40f7c638b79d25984aa7 Joe Ferris and Mike Burns committed with jferris Aug 3, 2012
Showing with 33 additions and 3 deletions.
  1. +9 −0 lib/turning/configuration.rb
  2. +1 −1 lib/turning/controller.rb
  3. +4 −2 lib/turning/railtie.rb
  4. +19 −0 spec/turning/configuration_spec.rb
View
9 lib/turning/configuration.rb
@@ -0,0 +1,9 @@
+module Turning
+ class Configuration
+ attr_writer :storage
+
+ def storage
+ @storage ||= FileStorage.new(Rails.root.join('public', 'static'))
+ end
+ end
+end
View
2 lib/turning/controller.rb
@@ -19,7 +19,7 @@ def view_path
end
def storage
- FileStorage.new(Rails.root.join('public', 'static'))
+ Rails.configuration.turning.storage
end
end
end
View
6 lib/turning/railtie.rb
@@ -1,12 +1,14 @@
require 'rails/railtie'
require 'turning/static_cascade'
require 'turning/file_storage'
+require 'turning/configuration'
module Turning
class Railtie < ::Rails::Railtie
+ config.turning = Configuration.new
+
initializer('turning.middleware') do
- config.app_middleware.use StaticCascade,
- FileStorage.new(Rails.root.join('public', 'static'))
+ config.app_middleware.use StaticCascade, config.turning.storage
end
end
end
View
19 spec/turning/configuration_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+require 'turning/configuration'
+require 'turning/file_storage'
+
+describe Turning::Configuration do
+ it 'has a default storage backend' do
+ storage = stub('storage')
+ Turning::FileStorage.stubs(new: storage)
+ configuration = Turning::Configuration.new
+ configuration.storage.should == storage
+ Turning::FileStorage.should have_received(:new).with(Rails.root.join('public/static'))
+ end
+
+ it 'can change the storage backend' do
+ configuration = Turning::Configuration.new
+ configuration.storage = :anything
+ configuration.storage.should == :anything
+ end
+end

0 comments on commit 595c915

Please sign in to comment.