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 module Config
extend self extend self


def configure def configure; yield self end
yield self
def reset_defaults
@fabricator_path = @path_prefix = @active_support = nil
end end


def fabricator_path def fabricator_path
OPTIONS[:fabricator_path] @fabricator_path ||= ['test/fabricators', 'spec/fabricators']
end end
alias fabricator_dir fabricator_path alias fabricator_dir fabricator_path


def fabricator_path=(folders) def fabricator_path=(folders)
OPTIONS[:fabricator_path] = (Array.new << folders).flatten @fabricator_path = (Array.new << folders).flatten
end end
alias fabricator_dir= fabricator_path= alias fabricator_dir= fabricator_path=


attr_writer :path_prefix
def path_prefix def path_prefix
OPTIONS[:path_prefix] @path_prefix ||= defined?(Rails) ? Rails.root : "."
end

def path_prefix=(prefix)
OPTIONS[:path_prefix] = prefix
end

def reset_defaults
OPTIONS.replace(DEFAULTS)
end end


def active_support? def active_support?
@active_support ||= defined?(ActiveSupport) @active_support ||= defined?(ActiveSupport)
end end


def register_with_steps? attr_writer :register_with_steps
OPTIONS[:register_with_steps] def register_with_steps?; @register_with_steps end
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)
end end
end end

0 comments on commit 4960c01

Please sign in to comment.