lib/option_initializer.rb in option_initializer-1.1.2 vs lib/option_initializer.rb in option_initializer-1.1.3
- old
+ new
@@ -17,12 +17,12 @@
attr_reader :options
alias to_h options
const_set :VALIDATORS, []
- def initialize base, options
- validate options
+ def initialize base, options, need_validation
+ validate options if need_validation
@base = base
@options = options
end
def new *args, &block
@@ -48,11 +48,11 @@
@base.new(*args, &block)
end
def merge opts
validate opts
- self.class.new @base, @options.merge(opts)
+ self.class.new @base, @options.merge(opts), false
end
def validate hash
self.class.const_get(:VALIDATORS).each do |validator|
hash.each do |k, v|
@@ -94,15 +94,15 @@
# define_singleton_method not available on 1.8
singleton = class << self; self end
singleton.send :undef_method, sym if singleton.method_defined?(sym)
singleton.send :define_method, sym do |*v, &b|
if b && v.empty?
- oi.new self, sym => b
+ oi.new self, {sym => b}, true
elsif b && !v.empty?
raise ArgumentError,
"wrong number of arguments (#{v.length} for 0 when block given)"
elsif v.length == 1
- oi.new self, sym => v.first
+ oi.new self, {sym => v.first}, true
else
raise ArgumentError,
"wrong number of arguments (#{v.length} for 1)"
end
end