class StaticShellTemplates::Include

Attributes

header[R]
source[R]
template[R]

Public Class Methods

new(template, logger = Logger.new(STDOUT)) click to toggle source
# File lib/static_shell_templates.rb, line 36
def initialize(template, logger = Logger.new(STDOUT))
  @template = template
  @header = template
  @logger = logger
  # @logger.debug template
  source_match = template.match(/source: (?<source>.*)/)
  @source = URI source_match['source']
end

Public Instance Methods

content() click to toggle source
# File lib/static_shell_templates.rb, line 45
def content
  response = fetch @source

  response.body
end
output() click to toggle source
# File lib/static_shell_templates.rb, line 67
    def output
      %(#{@header}
#{content}
#template:end)
    end

Private Instance Methods

fetch(uri_str, limit = 10) click to toggle source
# File lib/static_shell_templates.rb, line 51
        def fetch(uri_str, limit = 10)
  raise ArgumentError, 'too many HTTP redirects' if limit == 0

  response = Net::HTTP.get_response(URI(uri_str))

  case response
  when Net::HTTPSuccess then
    response
  when Net::HTTPRedirection then
    location = response['location']
    fetch(location, limit - 1)
  else
    fail Error, "Content not found: #{@source}"
  end
end