Class: Postpeek::Configuration

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

Constant Summary collapse

DEFAULTS =
{
  storage_path: nil,
  storage_backend: :file_system,
  unknown_encoding: :raise,
  max_emails: 500,
  auto_prune: true,
  open_in_browser: false,
  after_save: [],
  metadata_builders: []
}.freeze
VALID_UNKNOWN_ENCODING_VALUES =
%i[raise warn skip].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



24
25
26
# File 'lib/postpeek/configuration.rb', line 24

def initialize
  DEFAULTS.each { |key, value| public_send(:"#{key}=", deep_dup(value)) }
end

Instance Attribute Details

#after_saveObject

Returns the value of attribute after_save.



20
21
22
# File 'lib/postpeek/configuration.rb', line 20

def after_save
  @after_save
end

#auto_pruneObject

Returns the value of attribute auto_prune.



20
21
22
# File 'lib/postpeek/configuration.rb', line 20

def auto_prune
  @auto_prune
end

#max_emailsObject

Returns the value of attribute max_emails.



20
21
22
# File 'lib/postpeek/configuration.rb', line 20

def max_emails
  @max_emails
end

#metadata_buildersObject

Returns the value of attribute metadata_builders.



20
21
22
# File 'lib/postpeek/configuration.rb', line 20

def 
  @metadata_builders
end

#open_in_browserObject

Returns the value of attribute open_in_browser.



20
21
22
# File 'lib/postpeek/configuration.rb', line 20

def open_in_browser
  @open_in_browser
end

#storage_backendObject

Returns the value of attribute storage_backend.



20
21
22
# File 'lib/postpeek/configuration.rb', line 20

def storage_backend
  @storage_backend
end

#storage_pathObject

Returns the value of attribute storage_path.



20
21
22
# File 'lib/postpeek/configuration.rb', line 20

def storage_path
  @storage_path
end

#unknown_encodingObject

Returns the value of attribute unknown_encoding.



20
21
22
# File 'lib/postpeek/configuration.rb', line 20

def unknown_encoding
  @unknown_encoding
end

Instance Method Details

#after_save_hook(callable = nil, &block) ⇒ Object



36
37
38
# File 'lib/postpeek/configuration.rb', line 36

def after_save_hook(callable = nil, &block)
  after_save << (callable || block)
end

#metadata_builder(callable = nil, &block) ⇒ Object



40
41
42
# File 'lib/postpeek/configuration.rb', line 40

def (callable = nil, &block)
   << (callable || block)
end

#resolved_storage_pathObject



28
29
30
31
32
33
34
# File 'lib/postpeek/configuration.rb', line 28

def resolved_storage_path
  path = storage_path ||
         (defined?(Rails) && Rails.respond_to?(:root) && Rails.root ? Rails.root.join("tmp", "postpeek") : nil) ||
         Pathname.new(Dir.pwd).join("tmp", "postpeek")

  Pathname.new(path)
end

#validate!Object



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/postpeek/configuration.rb', line 44

def validate!
  unless VALID_UNKNOWN_ENCODING_VALUES.include?(unknown_encoding)
    raise ArgumentError,
          "unknown_encoding must be one of #{VALID_UNKNOWN_ENCODING_VALUES.inspect}, " \
          "got #{unknown_encoding.inspect}"
  end

  if !max_emails.nil? && (!max_emails.is_a?(Integer) || max_emails <= 0)
    raise ArgumentError, "max_emails must be a positive integer or nil, got #{max_emails.inspect}"
  end

  self
end