Sha256: 113c500fb6fea24234392119de1dfe404315f43c7ca58461deffea49dab95bff

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

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


# 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, :parent_module

      # 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)
        # Store the parent module in case we need it later
        @parent_module = Module.nesting.last
      end

    end

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
saddle-0.0.33 lib/saddle.rb
saddle-0.0.32 lib/saddle.rb
saddle-0.0.31 lib/saddle.rb
saddle-0.0.30 lib/saddle.rb