Skip to content

Commit

Permalink
locking down facets, making sure that object responds to dynamic methods
Browse files Browse the repository at this point in the history
  • Loading branch information
christfo committed Mar 21, 2012
1 parent ccbc140 commit 774abbb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ group :development do
gem 'rcov', :platforms => :mri_18
end

gem "facets"
gem "facets", "= 2.9.2"
12 changes: 11 additions & 1 deletion lib/detagger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@ def detag( value, targets = detag_chain, resolved = [] )
value
end

def method_missing( method, *args, &blk )
def split_method(method)
access, orig_method = *method.to_s.scan(/^(detag|raw)_(.+)$/).flatten
end

def method_missing( method, *args, &blk )
access, orig_method = split_method( method )
unless orig_method && target = [*detag_chain].find {|t| t.respond_to?( orig_method.to_sym )}
super(method,*args,&blk)
else
Expand All @@ -69,6 +73,12 @@ def method_missing( method, *args, &blk )
end
end

def respond_to?( method )
access, orig_method = split_method( method )
return true if orig_method && [*detag_chain].find {|t| t.respond_to?( orig_method.to_sym )}
super(method)
end

def unless_flag( flag, &blk )
unless self.send("detag_#{flag}")
yield blk
Expand Down
5 changes: 5 additions & 0 deletions spec/detagger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ def mike; "sue:soph:sue:jim:" end
@options. should respond_to :drill_down_ref
end

it "will respond to detag* and raw* mehtods" do
@options. should respond_to :detag_bob
@options. should respond_to :raw_bob
end

it "will give a value for inputs" do
@options.bob.should == "henry:"
@options.sue.should == "mary"
Expand Down

0 comments on commit 774abbb

Please sign in to comment.