Class: Prawn::SVG::UrlLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/svg/url_loader.rb

Constant Summary collapse

Error =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(enable_cache: false, enable_web: true, enable_file_with_root: nil) ⇒ UrlLoader

Returns a new instance of UrlLoader.



6
7
8
9
10
11
12
13
14
# File 'lib/prawn/svg/url_loader.rb', line 6

def initialize(enable_cache: false, enable_web: true, enable_file_with_root: nil)
  @url_cache = {}
  @enable_cache = enable_cache

  @loaders = []
  loaders << Prawn::SVG::Loaders::Data.new
  loaders << Prawn::SVG::Loaders::Web.new if enable_web
  loaders << Prawn::SVG::Loaders::File.new(enable_file_with_root) if enable_file_with_root
end

Instance Attribute Details

#enable_cacheObject (readonly)

Returns the value of attribute enable_cache.



4
5
6
# File 'lib/prawn/svg/url_loader.rb', line 4

def enable_cache
  @enable_cache
end

#loadersObject (readonly)

Returns the value of attribute loaders.



4
5
6
# File 'lib/prawn/svg/url_loader.rb', line 4

def loaders
  @loaders
end

Instance Method Details

#add_to_cache(url, data) ⇒ Object



20
21
22
# File 'lib/prawn/svg/url_loader.rb', line 20

def add_to_cache(url, data)
  @url_cache[url] = data
end

#load(url) ⇒ Object



16
17
18
# File 'lib/prawn/svg/url_loader.rb', line 16

def load(url)
  retrieve_from_cache(url) || perform_and_cache(url)
end

#retrieve_from_cache(url) ⇒ Object



24
25
26
# File 'lib/prawn/svg/url_loader.rb', line 24

def retrieve_from_cache(url)
  @url_cache[url]
end