lib/tumblr/helpers.rb in tumblr_client-0.6.11 vs lib/tumblr/helpers.rb in tumblr_client-0.7.0

- old
+ new

@@ -1,14 +1,19 @@ module Tumblr - class Client - module Helper - - def valid_options(valid_opts, opts) - bad_opts = opts.select { |val| !valid_opts.include?(val) } - if !bad_opts.empty? - raise Exception, "Invalid options passed, Only #{valid_opts} allowed." - end - return true + module Helper + + def validate_options(valid_opts, opts) + bad_opts = opts.select { |val| !valid_opts.include?(val) } + if bad_opts.any? + raise ArgumentError.new "Invalid options (#{bad_opts.keys.join(', ')}) passed, only #{valid_opts} allowed." end end + + def validate_no_collision(options, attributes) + count = attributes.count { |attr| options.has_key?(attr) } + if count > 1 + raise ArgumentError.new "Can only use one of: #{attributes.join(', ')} (Found #{count})" + end + end + end end