Sha256: c4c7e833100c83f66af8895e2ec68b4e72e5498bf2f28b03a57d204bdc53e1ae

Contents?: true

Size: 724 Bytes

Versions: 3

Compression:

Stored size: 724 Bytes

Contents

require "emites/resources/hooks"

module Emites
  module Resources
    class Base
      include Wisper::Publisher
      extend Hooks

      attr_accessor :http

      def initialize(http)
        @http = http
      end

      protected

      def respond_with_collection(response, naked_klass = entity_klass)
        Emites::Entities::Collection.build(response, naked_klass)
      end

      def respond_with_entity(response, naked_klass = entity_klass)
        naked_klass.new(response.parsed_body)
      end

      def base_klass
        @base_klass ||= self.class.name.split("::").last
      end

      def entity_klass
        @entity_klass ||= Emites::Entities.const_get(base_klass.to_sym)
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
emites-client-0.1.4 lib/emites/resources/base.rb
emites-client-0.1.3 lib/emites/resources/base.rb
emites-client-0.1.2 lib/emites/resources/base.rb