class ActiveLoader::ContentLoader

Attributes

path[R]

Public Class Methods

new(path) click to toggle source
# File lib/active_loader/content_loader.rb, line 5
def initialize(path)
  @path = path
end

Public Instance Methods

call() click to toggle source
# File lib/active_loader/content_loader.rb, line 9
def call
  return default_content unless path

  if url?
    require "http"
    HTTP.get(path).to_s
  elsif file?
    IO.read(path)
  else
    path
  end
end

Private Instance Methods

default_content() click to toggle source
# File lib/active_loader/content_loader.rb, line 26
def default_content
  "{}"
end
file?() click to toggle source
# File lib/active_loader/content_loader.rb, line 39
def file?
  File.file?(path)
end
url?() click to toggle source
# File lib/active_loader/content_loader.rb, line 30
def url?
  return false if path.empty?

  require "uri"
  !!URI.parse(path).scheme
rescue URI::BadURIError, URI::InvalidURIError
  false
end