Sha256: e136c26c00330ec9971cfceb76d406862c008c4280d24dd930bc450d94385bdc

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

module Pesapal
  # Hooks Pesapal to extend Rails and/or modify the initialization process.
  class Railtie < Rails::Railtie
    # Loads pesapal credentials from initializer file depending on environment
    # and fallback to default values if anything goes wrong.
    initializer 'pesapal.load_credentials' do
      path_to_yaml = "#{Rails.root}/config/pesapal.yml"
      if File.exist?(path_to_yaml)
        begin
          config.pesapal_credentials = YAML.load(IO.read(path_to_yaml))[Rails.env]
        rescue Errno::ENOENT
          logger.info('YAML configuration file couldn\'t be found.')
          return
        rescue Psych::SyntaxError
          logger.info('YAML configuration file contains invalid syntax. Will use using defaults.')
          return
        end
      else
        config.pesapal_credentials = { callback_url: 'http://0.0.0.0:3000/pesapal/callback',
                                       consumer_key: '<YOUR_CONSUMER_KEY>',
                                       consumer_secret: '<YOUR_CONSUMER_SECRET>'
                                      }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pesapal-1.8.0 lib/pesapal/railtie.rb
pesapal-1.7.0 lib/pesapal/railtie.rb
pesapal-1.6.0 lib/pesapal/railtie.rb