Class: GpWebpay::Configuration

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

Defined Under Namespace

Classes: MerchantConfig

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



5
6
7
8
9
10
11
# File 'lib/gp_webpay/configuration.rb', line 5

def initialize
  @configurations = {}
  @parent_controller = 'AbstractController::Base'
  @mount_at = '/gp_webpay'
  @orders_controller = 'OrdersController'
  @cards_controller = 'CardsController'
end

Instance Attribute Details

#cards_controllerObject

Returns the value of attribute cards_controller.



3
4
5
# File 'lib/gp_webpay/configuration.rb', line 3

def cards_controller
  @cards_controller
end

#configurationsObject

Returns the value of attribute configurations.



3
4
5
# File 'lib/gp_webpay/configuration.rb', line 3

def configurations
  @configurations
end

#mount_atObject

Returns the value of attribute mount_at.



3
4
5
# File 'lib/gp_webpay/configuration.rb', line 3

def mount_at
  @mount_at
end

#orders_controllerObject

Returns the value of attribute orders_controller.



3
4
5
# File 'lib/gp_webpay/configuration.rb', line 3

def orders_controller
  @orders_controller
end

#parent_controllerObject

Returns the value of attribute parent_controller.



3
4
5
# File 'lib/gp_webpay/configuration.rb', line 3

def parent_controller
  @parent_controller
end

Instance Method Details

#[](config_name) ⇒ Object



17
18
19
20
21
# File 'lib/gp_webpay/configuration.rb', line 17

def [](config_name)
  return if config_name.blank?

  @configurations[config_name] || find_configuration_by_merchant_number(config_name)
end

#add_configuration(merchant_number:, default: false) {|| ... } ⇒ Object

Yields:

  • ()


30
31
32
33
34
# File 'lib/gp_webpay/configuration.rb', line 30

def add_configuration(merchant_number:, default: false)
  @configurations[merchant_number] = MerchantConfig.new(merchant_number)
  yield(@configurations[merchant_number])
  @configurations[:default] = @configurations[merchant_number] if default || !@configurations[:default]
end

#defaultObject



13
14
15
# File 'lib/gp_webpay/configuration.rb', line 13

def default
  @configurations[:default]
end

#find_configuration_by_merchant_number(merchant_number) ⇒ Object



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

def find_configuration_by_merchant_number(merchant_number)
  config = @configurations.find { |_key, value| value.merchant_number.to_s == merchant_number.to_s }
  return nil if config.blank?

  config[-1]
end

#remove_configuration(merchant_number:) ⇒ Object



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

def remove_configuration(merchant_number:)
  @configurations.delete(merchant_number)
  @configurations[:default] = @configurations[@configurations.keys[0]]
end