Sha256: 3b7751038dc9f909e8122ee4b9337b0d0d252e6f0a4e478c924e697aa67d95ee

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

require 'saddle/client_attributes'
require 'saddle/method_tree_builder'
require 'saddle/options'
require 'saddle/requester'


# Inherit your client implementation from Saddle::Client
# then call YourCrayClient.create to get a client instance.


module Saddle

  class Client

    extend MethodTreeBuilder
    extend Options

    class << self
      attr_accessor :additional_middlewares

      # Once your implementation is written, this is the magic you need to
      # create a client instance.
      def create(opt={})
        self.build_tree(
          Saddle::Requester.new(
            self,
            default_options.merge(opt)
          )
        )
      end

      def inherited(obj)
        # Clone the parent's additional_middlewares
        obj.additional_middlewares = if defined?(obj.superclass.additional_middlewares)
          (obj.superclass.additional_middlewares || []).clone
        else
          []
        end
        # Add additional client attributes
        obj.send(:include, Saddle::ClientAttributes)
      end

      # Name of the module that contains the implementing client
      def root_namespace
        module_nests = self.name.split('::')
        module_nests.length > 1 ? module_nests[-2] : module_nests.last
      end

    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
saddle-0.0.27 lib/saddle.rb
saddle-0.0.26 lib/saddle.rb
saddle-0.0.25 lib/saddle.rb