Sha256: 4107e84d3c02e23692b957a0b2e095708d0402d4100364f27230c4936a4303c7

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

module ActiveESP
  # A +Provider+ in ActiveESP is an individual ESP class that implements the required
  # methods to conform to a +Provider+ protocol.
  #
  # To make things work smoothly, the framework expects a +Provider+ to extend from
  # +ActiveESP::Providers::Base+. This allows common functionality to be shared
  # amongst the providers as well as exceptions to be raised when the provider
  # doesn't implement a required method.
  #
  module Providers
    class Base
      implements ActiveESP::Providers::Interface
      # Returns or sets the API key
      #
      # @return [String]
      attr_accessor :api_key

      # Sets the endpoint base URL without a trailing slash
      #
      # @return [String]
      attr_writer :endpoint
      cattr_accessor :endpoint

      # Initialize object with an optional attributes hash
      #
      # @param [Hash] attributes An optional hash of attributes to assign to the new instance
      def initialize(attributes = nil)
        if attributes.is_a? Hash
          attributes.each do |key, value|
            self.send(key.to_s + "=", value)
          end
        end
      end

      def endpoint
        if defined?(@endpoint)
          @endpoint
        elsif self.class.endpoint
          self.class.endpoint
        elsif superclass != Object && superclass.endpoint
          superclass.endpoint
        else
          @endpoint ||= ''
        end
      end

    end

    class MethodNotImplementedException < Exception; end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_esp-0.1.0.alpha4 lib/active_esp/providers/base.rb
active_esp-0.1.0.alpha3 lib/active_esp/providers/base.rb
active_esp-0.1.0.alpha2 lib/active_esp/providers/base.rb
active_esp-0.1.0.alpha1 lib/active_esp/providers/base.rb