Skip to content

Commit

Permalink
Added Config#configure
Browse files Browse the repository at this point in the history
  • Loading branch information
ianwhite committed Dec 30, 2008
1 parent 86b9924 commit 0a18a2c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
14 changes: 10 additions & 4 deletions lib/pickle/config.rb
Expand Up @@ -5,10 +5,16 @@ class Config
attr_writer :adapters, :factories, :mappings

# default configuration object
def self.default
returning(@default ||= new) do |config|
yield(config) if block_given?
end
def self.default(&block)
returning(@default ||= new) {|config| config.configure(&block) if block_given?}
end

def initialize(&block)
configure(&block) if block_given?
end

def configure(&block)
yield(self)
end

def adapters
Expand Down
11 changes: 9 additions & 2 deletions spec/lib/pickle_config_spec.rb
Expand Up @@ -73,11 +73,18 @@ class SomeAdapter; end
@config.map 'foo', 'bar', :to => 'faz'
end

it "should create {:search => '(?:foo|bar)', :replace => 'faz'} mapping" do
it "should create OpenStruct(search: '(?:foo|bar)', replace: 'faz') mapping" do
@config.mappings.first.should == OpenStruct.new(:search => '(?:foo|bar)', :replace => 'faz')
end
end


it "#configure(&block) should execiute on self" do
@config.should_receive(:foo).with(:bar)
@config.configure do |c|
c.foo :bar
end
end

describe ".default (class method)" do
it "should refer to same object" do
Pickle::Config.default.should == Pickle::Config.default
Expand Down

0 comments on commit 0a18a2c

Please sign in to comment.