Module: PaintbrushSupport::Configuration

Defined in:
lib/paintbrush_support/configuration.rb

Overview

Provides a configuration interface for Paintbrush features, allows disabling colorization.

Usage:

“‘ruby Paintbrush::Configuration.colorize = false “`

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject (readonly)

Returns the value of attribute configuration.



19
20
21
# File 'lib/paintbrush_support/configuration.rb', line 19

def configuration
  @configuration
end

.defaultsObject (readonly)

Returns the value of attribute defaults.



19
20
21
# File 'lib/paintbrush_support/configuration.rb', line 19

def defaults
  @defaults
end

Class Method Details

.colorize=(val) ⇒ Object



21
22
23
# File 'lib/paintbrush_support/configuration.rb', line 21

def colorize=(val)
  configuration[:colorize] = val
end

.colorize?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/paintbrush_support/configuration.rb', line 25

def colorize?
  configuration.fetch(:colorize, defaults[:colorize])
end

.resetObject



29
30
31
# File 'lib/paintbrush_support/configuration.rb', line 29

def reset
  @configuration = {}
end

.with_configuration(**options, &block) ⇒ Object



33
34
35
36
37
# File 'lib/paintbrush_support/configuration.rb', line 33

def with_configuration(**options, &block)
  previous = configuration.dup
  options.compact.each { |key, value| configuration[key] = value unless configuration.key?(key) }
  block.call.tap { @configuration = previous }
end