Class: NtiReceiptBuilder::Configuration

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

Overview

Runtime configuration.

Class references are held by NAME, never as Class objects. Retaining a reloadable application class here would pin that class and its whole constant tree past every development reload, and would serve a stale class after the host reloads its code.

Constant Summary collapse

DEFAULT_CURRENCY_UNIT =
''
DEFAULT_DATETIME_FORMAT =
'%m/%d/%Y %I:%M %p'
DEFAULT_TEMPLATE_CLASS =
'NtiReceiptBuilder::Template'
DEFAULT_PRINT_STYLESHEET =
'nti_receipt_builder'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



22
23
24
25
26
27
28
# File 'lib/nti_receipt_builder/configuration.rb', line 22

def initialize
  @currency_unit = DEFAULT_CURRENCY_UNIT
  @datetime_format = DEFAULT_DATETIME_FORMAT
  @print_stylesheet = DEFAULT_PRINT_STYLESHEET
  @variables_class_name = nil
  @template_class_name = DEFAULT_TEMPLATE_CLASS
end

Instance Attribute Details

#currency_unitObject

Returns the value of attribute currency_unit.



15
16
17
# File 'lib/nti_receipt_builder/configuration.rb', line 15

def currency_unit
  @currency_unit
end

#datetime_formatObject

Returns the value of attribute datetime_format.



15
16
17
# File 'lib/nti_receipt_builder/configuration.rb', line 15

def datetime_format
  @datetime_format
end

Stylesheet(s) the standalone print document loads — a name or an array of names. Defaults to the gem's own so print output is correct without host configuration. A host whose bundle does not include this gem's CSS should list both, e.g. ['app', 'nti_receipt_builder'].



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

def print_stylesheet
  @print_stylesheet
end

#template_class_nameObject (readonly)

Returns the value of attribute template_class_name.



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

def template_class_name
  @template_class_name
end

#variables_class_nameObject (readonly)

Returns the value of attribute variables_class_name.



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

def variables_class_name
  @variables_class_name
end

Instance Method Details

#template_classObject



47
48
49
# File 'lib/nti_receipt_builder/configuration.rb', line 47

def template_class
  @template_class_name.constantize
end

#template_class=(value) ⇒ Object



43
44
45
# File 'lib/nti_receipt_builder/configuration.rb', line 43

def template_class=(value)
  @template_class_name = class_name_for(value)
end

#variables_classObject



34
35
36
37
38
39
40
41
# File 'lib/nti_receipt_builder/configuration.rb', line 34

def variables_class
  if @variables_class_name.nil?
    raise NotConfiguredError,
          'NtiReceiptBuilder.config.variables_class must be set to a NtiReceiptBuilder::Variables subclass'
  end

  @variables_class_name.constantize
end

#variables_class=(value) ⇒ Object



30
31
32
# File 'lib/nti_receipt_builder/configuration.rb', line 30

def variables_class=(value)
  @variables_class_name = class_name_for(value)
end