Sha256: 745aa4b6b437a2240a26246e0083cfbe587f1b128f81f543e037451f612f84f8

Contents?: true

Size: 1.02 KB

Versions: 9

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module ActionTracker
  class ClientNotConfiguredError < StandardError; end
  class InvalidTrackingMethodError < StandardError; end

  class Config
    VALID_TRACKING_METHODS = [
      :inline, :custom, :test
    ].freeze

    attr_writer :api_url, :api_key, :api_secret, :custom_worker_proc

    def api_url
      @api_url || raise(ActionTracker::ClientNotConfiguredError, missing_value: :api_url)
    end

    def api_key
      @api_key || raise(ActionTracker::ClientNotConfiguredError, missing_value: :api_key)
    end

    def api_secret
      @api_secret || raise(ActionTracker::ClientNotConfiguredError, missing_value: :api_secret)
    end

    def tracking_method
      @tracking_method ||= :inline
    end

    def tracking_method=(value)
      raise(InvalidTrackingMethodError, value) unless VALID_TRACKING_METHODS.include?(value)

      @tracking_method = value
    end

    def custom_worker_proc
      @custom_worker_proc ||= ->(form) { ActionTracker::Workers::Inline.new(form).perform }
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
action_tracker_client-0.1.8 lib/action_tracker/config.rb
action_tracker_client-0.1.7 lib/action_tracker/config.rb
action_tracker_client-0.1.6 lib/action_tracker/config.rb
action_tracker_client-0.1.5 lib/action_tracker/config.rb
action_tracker_client-0.1.4 lib/action_tracker/config.rb
action_tracker_client-0.1.3 lib/action_tracker/config.rb
action_tracker_client-0.1.2 lib/action_tracker/config.rb
action_tracker_client-0.1.1 lib/action_tracker/config.rb
action_tracker_client-0.1.0 lib/action_tracker/config.rb