File: private_helpers.rb

package info (click to toggle)
libshoulda-ruby 2.10.3-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 880 kB
  • ctags: 726
  • sloc: ruby: 5,764; makefile: 6
file content (13 lines) | stat: -rw-r--r-- 546 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
module Shoulda # :nodoc:
  module Private # :nodoc:
    # Returns the values for the entries in the args hash who's keys are listed in the wanted array.
    # Will raise if there are keys in the args hash that aren't listed.
    def get_options!(args, *wanted)
      ret  = []
      opts = (args.last.is_a?(Hash) ? args.pop : {})
      wanted.each {|w| ret << opts.delete(w)}
      raise ArgumentError, "Unsupported options given: #{opts.keys.join(', ')}" unless opts.keys.empty?
      return wanted.size == 1 ? ret.first : ret
    end
  end
end