From 4960c017ba290b1e8f2f983abce0e9d7a0ab7598 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Tue, 17 Jul 2012 15:45:20 -0400 Subject: [PATCH] Replace options hash with memoized instance vars --- lib/fabrication/config.rb | 39 ++++++++++----------------------------- 1 file changed, 10 insertions(+), 29 deletions(-) diff --git a/lib/fabrication/config.rb b/lib/fabrication/config.rb index d6b873fb..b13ff23a 100644 --- a/lib/fabrication/config.rb +++ b/lib/fabrication/config.rb @@ -2,51 +2,32 @@ module Fabrication module Config extend self - def configure - yield self + def configure; yield self end + + def reset_defaults + @fabricator_path = @path_prefix = @active_support = nil end def fabricator_path - OPTIONS[:fabricator_path] + @fabricator_path ||= ['test/fabricators', 'spec/fabricators'] end alias fabricator_dir fabricator_path def fabricator_path=(folders) - OPTIONS[:fabricator_path] = (Array.new << folders).flatten + @fabricator_path = (Array.new << folders).flatten end alias fabricator_dir= fabricator_path= + attr_writer :path_prefix def path_prefix - OPTIONS[:path_prefix] - end - - def path_prefix=(prefix) - OPTIONS[:path_prefix] = prefix - end - - def reset_defaults - OPTIONS.replace(DEFAULTS) + @path_prefix ||= defined?(Rails) ? Rails.root : "." end def active_support? @active_support ||= defined?(ActiveSupport) end - def register_with_steps? - OPTIONS[:register_with_steps] - end - - def register_with_steps=(register) - OPTIONS[:register_with_steps] = register - end - - private - - DEFAULTS = { - fabricator_path: ['test/fabricators', 'spec/fabricators'], - register_with_steps: false, - path_prefix: defined?(Rails) ? Rails.root : "." - } - OPTIONS = {}.merge!(DEFAULTS) + attr_writer :register_with_steps + def register_with_steps?; @register_with_steps end end end