Class: WickedPdf::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/wicked_pdf/configuration.rb

Overview

Global gem configuration, set via WickedPdf.configure or by assigning a Hash to WickedPdf.config (kept for backward compatibility).

Two kinds of values live here:

  • Typed settings, declared as accessors below, which control the gem itself (binary location, middleware URLs, asset handling).
  • default_options, a Hash of wkhtmltopdf render options (:footer, :orientation, :dpi, ...) merged under every render's own options. Unknown keys assigned through a Hash or #[]= land here.

Constant Summary collapse

SETTINGS =
[
  :exe_path,
  :basic_auth,
  :root_url,
  :default_protocol,
  :expect_gzipped_remote_assets,
  :enable_local_file_access
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



31
32
33
34
35
# File 'lib/wicked_pdf/configuration.rb', line 31

def initialize
  @basic_auth = false
  @enable_local_file_access = true
  @default_options = {}
end

Instance Attribute Details

#default_optionsObject (readonly)

Returns the value of attribute default_options.



23
24
25
# File 'lib/wicked_pdf/configuration.rb', line 23

def default_options
  @default_options
end

Class Method Details

.from_hash(hash) ⇒ Object



25
26
27
28
29
# File 'lib/wicked_pdf/configuration.rb', line 25

def self.from_hash(hash)
  new.tap do |config|
    (hash || {}).each { |key, value| config[key] = value }
  end
end

Instance Method Details

#[](key) ⇒ Object



45
46
47
# File 'lib/wicked_pdf/configuration.rb', line 45

def [](key)
  setting?(key) ? public_send(key) : default_options[key.to_sym]
end

#[]=(key, value) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/wicked_pdf/configuration.rb', line 37

def []=(key, value)
  if setting?(key)
    public_send("#{key}=", value)
  else
    default_options[key.to_sym] = value
  end
end

#to_hObject



49
50
51
52
# File 'lib/wicked_pdf/configuration.rb', line 49

def to_h
  settings = SETTINGS.to_h { |key| [key, public_send(key)] }
  settings.compact.merge(default_options)
end