Module: Sipity::Conversions::ConvertToPermanentUri

Defined in:
app/conversions/sipity/conversions/convert_to_permanent_uri.rb

Overview

Exposes a conversion method to take an input and transform it into a URL that the web application's maintainer pinky promises will resolve long into the future.

Constant Summary collapse

PERMANENT_URI_FORMAT =
"https://change.me/show/%s".freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(input) ⇒ Object

A convenience method so that you don't need to include the conversion module in your base class.


11
12
13
# File 'app/conversions/sipity/conversions/convert_to_permanent_uri.rb', line 11

def self.call(input)
  convert_to_permanent_uri(input)
end

.convert_to_permanent_uri(input) ⇒ Object (private)

Does its best to convert the input into a permanent url.


20
21
22
23
24
25
26
27
# File 'app/conversions/sipity/conversions/convert_to_permanent_uri.rb', line 20

def convert_to_permanent_uri(input)
  return convert_to_permanent_uri(input.id) if input.is_a?(Models::Sip)
  return convert_to_permanent_uri(input.sip_id) if input.respond_to?(:sip_id)
  return convert_to_permanent_uri(input.sip) if input.respond_to?(:sip)
  # TODO: The Sip key may not be a Fixed num
  return PERMANENT_URI_FORMAT % input if input.is_a?(Fixnum)
  fail Exceptions::PermanentUriConversionError, input
end

Instance Method Details

#convert_to_permanent_uri(input) ⇒ Object (private)

Does its best to convert the input into a permanent url.


20
21
22
23
24
25
26
27
# File 'app/conversions/sipity/conversions/convert_to_permanent_uri.rb', line 20

def convert_to_permanent_uri(input)
  return convert_to_permanent_uri(input.id) if input.is_a?(Models::Sip)
  return convert_to_permanent_uri(input.sip_id) if input.respond_to?(:sip_id)
  return convert_to_permanent_uri(input.sip) if input.respond_to?(:sip)
  # TODO: The Sip key may not be a Fixed num
  return PERMANENT_URI_FORMAT % input if input.is_a?(Fixnum)
  fail Exceptions::PermanentUriConversionError, input
end