module Straight::GatewayModule

This module should be included into your own class to extend it with Gateway functionality. For example, if you have a ActiveRecord model called Gateway, you can include GatewayModule into it and you'll now be able to do everything Straight::Gateway can do, but you'll also get AR Database storage funcionality, its validations etc.

The right way to implement this would be to do it the other way: inherit from Straight::Gateway, then include ActiveRecord, but at this point ActiveRecord doesn't work this way. Furthermore, some other libraries, like Sequel, also require you to inherit from them. Thus, the module.

When this module is included, it doesn't actually include all the methods, some are prepended (see Ruby docs on prepend). It is important specifically for getters and setters and as a general rule only getters and setters are prepended.

If you don't want to bother yourself with modules, please use Straight::Gateway class and simply create new instances of it. However, if you are contributing to the library, all new funcionality should go to either Straight::GatewayModule::Includable or Straight::GatewayModule::Prependable (most likely the former).

Constants

DEFAULT_STATUS_CHECK_SCHEDULE

Determines the algorithm for consequitive checks of the order status.

Public Class Methods

included(base) click to toggle source

Only add getters and setters for those properties in the extended class that don't already have them. This is very useful with ActiveRecord for example where we don't want to override AR getters and setters that set attributes.

# File lib/straight/gateway.rb, line 27
def self.included(base)
  base.class_eval do
    [
      :pubkey,
      :test_pubkey,
      :confirmations_required,
      :status_check_schedule,
      :blockchain_adapters,
      :exchange_rate_adapters,
      :order_callbacks,
      :order_class,
      :default_currency,
      :name,
      :address_provider,
      :address_provider_type,
      :address_derivation_scheme,
      :test_mode
    ].each do |field|
      attr_reader field unless base.method_defined?(field)
      attr_writer field unless base.method_defined?("#{field}=")
      prepend Prependable
      include Includable
    end
  end
end