1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
class URI::XGrowlResource < URI::Generic
DEFAULT_PORT = nil
COMPONENT = [ :scheme, :unique_id ]
UNIQUE_ID_REGEXP = /\A[\w-]+\z/
attr_reader :unique_id
def self.build args
tmp = URI::Util.make_components_hash self, args
if tmp[:unique_id] then
tmp[:host] = tmp[:unique_id]
else
tmp[:host] = ''
end
super tmp
end
def initialize *args
super
@unique_id = nil
if UNIQUE_ID_REGEXP =~ @host then
if args[-1] then # arg_check
self.unique_id = @host
else
set_unique_id @host
end
else
raise URI::InvalidComponentError,
"unrecognized opaque part for x-growl-resource URL: #{@host}"
end
end
def to_s # :nodoc:
"#{@scheme}://#{@unique_id}"
end
def unique_id= v
check_unique_id v
set_unique_id v
end
# :stopdoc:
protected
def set_unique_id v
@unique_id = v
end
private
def check_unique_id v
return true unless v
return true if v.empty?
if parser.regexp[:HOST] !~ v or UNIQUE_ID_REGEXP !~ v then
raise InvalidComponentError,
"bad component (expected unique ID component): #{v}"
end
true
end
end
module URI # :nodoc:
@@schemes['X-GROWL-RESOURCE'] = URI::XGrowlResource
end
|