Skip to content
This repository has been archived by the owner on Mar 15, 2021. It is now read-only.

Commit

Permalink
Replace options hash with memoized instance vars
Browse files Browse the repository at this point in the history
  • Loading branch information
paulelliott committed Jul 17, 2012
1 parent b279db8 commit 4960c01
Showing 1 changed file with 10 additions and 29 deletions.
39 changes: 10 additions & 29 deletions lib/fabrication/config.rb
Expand Up @@ -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

0 comments on commit 4960c01

Please sign in to comment.