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

Modify Namespace method missing, only use caller when error #83

Merged
merged 1 commit into from
Nov 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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