Module: URITemplate::ClassMethods

Included in:
URITemplate
Defined in:
lib/uri_template.rb

Overview

Helper module which defines class methods for all uri template classes.

Instance Method Summary collapse

Instance Method Details

#convert(x) ⇒ URITemplate

Same as #try_convert but raises an ArgumentError when the given argument could not be converted.

Returns:

Raises:

  • ArgumentError if the argument is unconvertable



48
49
50
51
52
53
54
# File 'lib/uri_template.rb', line 48

def convert(x)
  o = self.try_convert(x)
  if o.nil?
    raise ArgumentError, "Expected to receive something that can be converted into a URITemplate of type #{self.inspect}, but got #{x.inspect}"
  end
  return o
end

#included(base) ⇒ Object



56
57
58
# File 'lib/uri_template.rb', line 56

def included(base)
  base.extend(ClassMethods)
end

#try_convert(x) ⇒ nil|{URITemplate}

Tries to convert the given argument into an URITemplate. Returns nil if this fails.

Returns:



34
35
36
37
38
39
40
41
42
# File 'lib/uri_template.rb', line 34

def try_convert(x)
  if x.kind_of? self
    return x
  elsif x.kind_of? String
    return self.new(x)
  else
    return nil
  end
end