Sha256: 43983e3b96342311563e69b38719ceda5109bcf6bd47bafb8a8a7ac152579812

Contents?: true

Size: 937 Bytes

Versions: 18

Compression:

Stored size: 937 Bytes

Contents

module JSONAPI
  class Operation
    attr_reader :resource_klass, :operation_type, :options

    def initialize(operation_type, resource_klass, options)
      @operation_type = operation_type
      @resource_klass = resource_klass
      @options = options
    end

    def process
      processor.process
    end

    private
    def processor
      self.class.processor_instance_for(resource_klass, operation_type, options)
    end

    class << self
      def processor_instance_for(resource_klass, operation_type, params)
        _processor_from_resource_type(resource_klass).new(resource_klass, operation_type, params)
      end

      def _processor_from_resource_type(resource_klass)
        processor = resource_klass.name.gsub(/Resource$/,'Processor').safe_constantize
        if processor.nil?
          processor = JSONAPI.configuration.default_processor_klass
        end

        return processor
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
jsonapi-resources-0.10.7 lib/jsonapi/operation.rb
jsonapi-resources-0.10.6 lib/jsonapi/operation.rb
jsonapi-resources-0.10.5 lib/jsonapi/operation.rb
jsonapi-resources-0.10.4 lib/jsonapi/operation.rb
jsonapi-resources-0.10.3 lib/jsonapi/operation.rb
jsonapi-resources-0.10.2 lib/jsonapi/operation.rb
jsonapi-resources-0.10.1 lib/jsonapi/operation.rb
jsonapi-resources-0.10.0 lib/jsonapi/operation.rb
jsonapi-resources-0.10.0.beta9 lib/jsonapi/operation.rb
jsonapi-resources-0.10.0.beta8 lib/jsonapi/operation.rb
jsonapi-resources-0.10.0.beta7 lib/jsonapi/operation.rb
jsonapi-resources-0.10.0.beta6 lib/jsonapi/operation.rb
jsonapi-resources-0.10.0.beta5 lib/jsonapi/operation.rb
jsonapi-resources-0.10.0.beta4 lib/jsonapi/operation.rb
jsonapi-resources-0.10.0.beta3 lib/jsonapi/operation.rb
jsonapi-resources-0.10.0.beta2.1 lib/jsonapi/operation.rb
jsonapi-resources-0.10.0.beta2 lib/jsonapi/operation.rb
jsonapi-resources-0.10.0.beta1 lib/jsonapi/operation.rb