Sha256: d0c94d61d5944516b803e2dd1f3104d1271d38aa556ff8c28fe4eb377e8d7001

Contents?: true

Size: 1.65 KB

Versions: 8

Compression:

Stored size: 1.65 KB

Contents

module Restly::Base::Includes
  extend ActiveSupport::Concern

  included do
    class_attribute :current_specification, instance_writer: false
  end

  module ClassMethods

    # Delegate stuff to client
    delegate :site, :site=, :format, :format=, to: :client

    def client
      return @client if @client
      @client = Restly::Client.new(nil, nil)
      @client.resource = self
      @client
    end

    def client=(client)
      raise Restly::Error::InvalidClient, "Client is invalid!" unless client.is_a?(Restly::Client)
      @client = client
      @client.resource = self
      @client
    end

    def has_specification
      self.current_specification = Restly::Base::Resource::Specification.new(self)

      self.fields = current_specification.fields

      self._accessible_attributes = accessible_attributes_configs.dup
      self._protected_attributes =  protected_attributes_configs.dup

      (self._accessible_attributes ||= {})[:default] = current_specification.accessible_attributes
      (self._protected_attributes ||= {})[:default] = current_specification.protected_attributes

      self._active_authorizer = current_specification.active_authorizer
    end

    def connection
      connection = @connection || Restly::Connection.tokenize(client, current_token)
      connection.cache ||= cache
      connection.cache_options = cache_options unless connection.cache_options.present?
      connection
    end

    def connection=(connection)
      raise InvalidConnection, "#{connection} is not a valid Restly::Connection" unless connection.is_a?(Restly::Connection)
      @connection = connection
    end

    def param_key
      resource_name
    end

  end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
restly-0.0.1.beta.5 lib/restly/base/includes.rb
restly-0.0.1.beta.4 lib/restly/base/includes.rb
restly-0.0.1.beta.3 lib/restly/base/includes.rb
restly-0.0.1.beta.2 lib/restly/base/includes.rb
restly-0.0.1.beta.1 lib/restly/base/includes.rb
restly-0.0.1.alpha.22 lib/restly/base/includes.rb
restly-0.0.1.alpha.19 lib/restly/base/includes.rb
restly-0.0.1.alpha.18 lib/restly/base/includes.rb