Sha256: 8cadb5042d60790e3e7ec8b63e18a5308d9089d5c9fdc0bdcf999e6a5e52937d

Contents?: true

Size: 1.31 KB

Versions: 5

Compression:

Stored size: 1.31 KB

Contents

module JSONAPI
  class OperationResult
    attr_accessor :code
    attr_accessor :meta
    attr_accessor :links
    attr_accessor :options

    def initialize(code, options = {})
      @code = code
      @options = options
      @meta = options.fetch(:meta, {})
      @links = options.fetch(:links, {})
    end
  end

  class ErrorsOperationResult < OperationResult
    attr_accessor :errors

    def initialize(code, errors, options = {})
      @errors = errors
      super(code, options)
    end
  end

  class ResourceOperationResult < OperationResult
    attr_accessor :resource

    def initialize(code, resource, options = {})
      @resource = resource
      super(code, options)
    end
  end

  class ResourcesOperationResult < OperationResult
    attr_accessor :resources, :pagination_params, :record_count

    def initialize(code, resources, options = {})
      @resources = resources
      @pagination_params = options.fetch(:pagination_params, {})
      @record_count = options[:record_count]
      super(code, options)
    end
  end

  class LinksObjectOperationResult < OperationResult
    attr_accessor :parent_resource, :relationship

    def initialize(code, parent_resource, relationship, options = {})
      @parent_resource = parent_resource
      @relationship = relationship
      super(code, options)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
jsonapi-resources-0.5.4 lib/jsonapi/operation_result.rb
jsonapi-resources-0.5.3 lib/jsonapi/operation_result.rb
jsonapi-resources-0.5.2 lib/jsonapi/operation_result.rb
jsonapi-resources-0.5.1 lib/jsonapi/operation_result.rb
jsonapi-resources-0.5.0 lib/jsonapi/operation_result.rb