Skip to content
This repository has been archived by the owner on Dec 9, 2017. It is now read-only.

Commit

Permalink
Merge pull request #83 from redding/jcr-ns-meth-miss-no-caller
Browse files Browse the repository at this point in the history
Modify `Namespace` method missing, only use `caller` when error
  • Loading branch information
jcredding committed Nov 6, 2013
2 parents 4991fb8 + 71edfb9 commit 9c5fab3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
5 changes: 4 additions & 1 deletion lib/ns-options/namespace.rb
Expand Up @@ -48,7 +48,10 @@ def respond_to?(meth)
end

def method_missing(meth, *args, &block)
@__data__.ns_method_missing(caller, meth, *args, &block)
@__data__.ns_method_missing(meth, *args, &block)
rescue StandardError => exception
exception.set_backtrace(caller)
raise exception
end

def ==(other_ns)
Expand Down
15 changes: 3 additions & 12 deletions lib/ns-options/namespace_data.rb
Expand Up @@ -129,7 +129,7 @@ def ns_respond_to?(meth)
false
end

def ns_method_missing(bt, meth, *args, &block)
def ns_method_missing(meth, *args, &block)
dslm = DslMethod.new(meth, *args, &block)

if is_namespace_reader?(dslm)
Expand All @@ -138,14 +138,9 @@ def ns_method_missing(bt, meth, *args, &block)
get_option(dslm.name)
elsif is_option_writer?(dslm)
add_option(dslm.name) unless has_option?(dslm.name)
begin
set_option(dslm.name, dslm.data)
rescue NsOptions::Option::CoerceError => err
error! bt, err # reraise this exception with a sane backtrace
end
set_option(dslm.name, dslm.data)
else # namespace writer or unknown
# raise a no meth err with a sane backtrace
error! bt, NoMethodError.new("undefined method `#{meth}' for #{@ns.inspect}")
raise NoMethodError.new("undefined method `#{meth}' for #{@ns.inspect}")
end
end

Expand All @@ -163,9 +158,5 @@ def is_option_writer?(dsl_method)
!has_namespace?(dsl_method.name) && dsl_method.has_args?
end

def error!(backtrace, exception)
exception.set_backtrace(backtrace); raise exception
end

end
end

0 comments on commit 9c5fab3

Please sign in to comment.