Sha256: 39b6427e66c9208eed27909c17aede4d15a856f5d34eda485971feec20538cbe

Contents?: true

Size: 1.31 KB

Versions: 7

Compression:

Stored size: 1.31 KB

Contents

require "ribose/resource_helper"

module Ribose
  class Base
    include Ribose::ResourceHelper

    def initialize(attributes = {})
      @attributes = attributes
      extract_base_attributes
      extract_local_attributes
    end

    private

    attr_reader :resource_id, :attributes, :client, :query

    # User provided options
    #
    # Some of the API endpoints has support for custom options,
    # for example sending a request as different client, pass
    # some query parameters and etc, and that's where this will
    # come in handy.
    #
    def custom_option
      { client: client, query: query }
    end

    # Extract Local Attributes
    #
    # This hook method let us extract sub-class specific attributes
    # And the way to do it is pretty simple, we only need to override
    # this method and extract the keys from the attributes hash. For
    # exmaple if `attributes` contains a has key `space_id` and we
    # want to extract it to a sub-class then we can do it as follow
    #
    #   def extract_local_attributes
    #     @space_id = attributes.delete(:space_id)
    #   end
    #
    def extract_local_attributes; end

    def extract_base_attributes
      @query = attributes.delete(:query)
      @client = attributes.delete(:client)
      @resource_id = attributes.delete(:resource_id)
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ribose-0.5.0 lib/ribose/base.rb
ribose-0.4.1 lib/ribose/base.rb
ribose-0.4.0 lib/ribose/base.rb
ribose-0.3.2 lib/ribose/base.rb
ribose-0.3.1 lib/ribose/base.rb
ribose-0.3.0 lib/ribose/base.rb
ribose-0.2.0 lib/ribose/base.rb