From 99be7d4e10634945b3ba4cd87e71d2defe65ad23 Mon Sep 17 00:00:00 2001 From: Alexander Merkulov Date: Sat, 27 Aug 2016 16:28:36 +0300 Subject: [PATCH] Ability to use shared directory --- lib/sprig/configuration.rb | 12 ++++++++++-- spec/lib/sprig/configuration_spec.rb | 13 +++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/sprig/configuration.rb b/lib/sprig/configuration.rb index ca7196e..9373fa0 100644 --- a/lib/sprig/configuration.rb +++ b/lib/sprig/configuration.rb @@ -1,10 +1,14 @@ module Sprig class Configuration - attr_writer :directory, :logger + attr_writer :directory, :logger, :shared_directory def directory - Rails.root.join(@directory || default_directory, Rails.env) + Rails.root.join(@directory || default_directory, source_directory) + end + + def shared_directory + @shared_directory end def logger @@ -13,6 +17,10 @@ def logger private + def source_directory + shared_directory || Rails.env + end + def default_directory 'db/seeds' end diff --git a/spec/lib/sprig/configuration_spec.rb b/spec/lib/sprig/configuration_spec.rb index a01a1e9..4d30f95 100644 --- a/spec/lib/sprig/configuration_spec.rb +++ b/spec/lib/sprig/configuration_spec.rb @@ -18,6 +18,19 @@ end end + describe "#shared_directory" do + it "returns nil by default" do + expect(subject.shared_directory).to be_nil + end + + it "returns a shared directory" do + subject.shared_directory = 'shared' + subject.directory = 'seed_files' + + expect(subject.directory.to_path).to eq('~/seed_files/shared') + end + end + describe "#logger" do it "returns an stdout logger by default" do logger = double('Logger')