Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Move storage into configuration

  • Loading branch information...
commit 595c91587b963abd74fe40f7c638b79d25984aa7 1 parent 80e65bb
Joe Ferris and Mike Burns authored jferris committed
9 lib/turning/configuration.rb
... ... @@ -0,0 +1,9 @@
  1 +module Turning
  2 + class Configuration
  3 + attr_writer :storage
  4 +
  5 + def storage
  6 + @storage ||= FileStorage.new(Rails.root.join('public', 'static'))
  7 + end
  8 + end
  9 +end
2  lib/turning/controller.rb
@@ -19,7 +19,7 @@ def view_path
19 19 end
20 20
21 21 def storage
22   - FileStorage.new(Rails.root.join('public', 'static'))
  22 + Rails.configuration.turning.storage
23 23 end
24 24 end
25 25 end
6 lib/turning/railtie.rb
... ... @@ -1,12 +1,14 @@
1 1 require 'rails/railtie'
2 2 require 'turning/static_cascade'
3 3 require 'turning/file_storage'
  4 +require 'turning/configuration'
4 5
5 6 module Turning
6 7 class Railtie < ::Rails::Railtie
  8 + config.turning = Configuration.new
  9 +
7 10 initializer('turning.middleware') do
8   - config.app_middleware.use StaticCascade,
9   - FileStorage.new(Rails.root.join('public', 'static'))
  11 + config.app_middleware.use StaticCascade, config.turning.storage
10 12 end
11 13 end
12 14 end
19 spec/turning/configuration_spec.rb
... ... @@ -0,0 +1,19 @@
  1 +require 'spec_helper'
  2 +require 'turning/configuration'
  3 +require 'turning/file_storage'
  4 +
  5 +describe Turning::Configuration do
  6 + it 'has a default storage backend' do
  7 + storage = stub('storage')
  8 + Turning::FileStorage.stubs(new: storage)
  9 + configuration = Turning::Configuration.new
  10 + configuration.storage.should == storage
  11 + Turning::FileStorage.should have_received(:new).with(Rails.root.join('public/static'))
  12 + end
  13 +
  14 + it 'can change the storage backend' do
  15 + configuration = Turning::Configuration.new
  16 + configuration.storage = :anything
  17 + configuration.storage.should == :anything
  18 + end
  19 +end

0 comments on commit 595c915

Please sign in to comment.
Something went wrong with that request. Please try again.