Sha256: 4344f19f1e1ee9e5396f2c4e3662ac90166e5e4aa29c1e1475f20868c2e736dd
Contents?: true
Size: 944 Bytes
Versions: 11
Compression:
Stored size: 944 Bytes
Contents
require 'engineyard/error' module EY module Collection class Abstract < Array def named(name) find {|x| x.name == name } end def match_one(name_part) named(name_part) || find_by_unambiguous_substring(name_part) end def match_one!(name_part) match_one(name_part) or raise invalid_error(name_part) end private def find_by_unambiguous_substring(name_part) candidates = find_all{|e| e.name[name_part] } if candidates.size > 1 raise ambiguous_error(name_part, candidates.map {|e| e.name}) end candidates.first end class << self attr_accessor :invalid_error, :ambiguous_error end def invalid_error(*args, &blk) self.class.invalid_error.new(*args, &blk) end def ambiguous_error(*args, &blk) self.class.ambiguous_error.new(*args, &blk) end end end end
Version data entries
11 entries across 11 versions & 1 rubygems