Sha256: c42f724d87166618059f4baee6c2564d0c14d24994c87fe4d7af3946ca9d7ffd

Contents?: true

Size: 1.2 KB

Versions: 16

Compression:

Stored size: 1.2 KB

Contents

module Interaction
  class ResultCreation
    attr_accessor :errors

    def initialize(params)
      @errors = []
      @substitution_values = params[:substitution_values]
      @owner = params[:owner]
      @query_version = get_query_version(params)
    end

    def execute
      compiler_result = @query_version.compile(substitution_values: @substitution_values)

      if compiler_result.error
        @errors << compiler_result.error.message
        return
      end

      result = Result.new(
        status: 'enqueued',
        parameters: compiler_result.effective_values,
        compiled_body: compiler_result.body,
        owner: @owner
      )

      result.query_version = @query_version if @query_version.persisted?

      result.save
      @errors << result.errors.full_messages if result.errors.any?

      result
    end

    private

    def get_query_version(params)
      case params[:query_version_id]
      when 'latest'
        QueryVersion.where(query_id: params[:query_id]).order('version DESC').limit(1)
      when nil
        QueryVersion.new(body: params[:body], parameters: params[:parameters] || {})
      else
        QueryVersion.find(params[:query_version_id])
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
aleph_analytics-0.4.9.pre.dev lib/interaction/result_creation.rb
aleph_analytics-0.4.8 lib/interaction/result_creation.rb
aleph_analytics-0.4.7 lib/interaction/result_creation.rb
aleph_analytics-0.4.4 lib/interaction/result_creation.rb
aleph_analytics-0.4.2 lib/interaction/result_creation.rb
aleph_analytics-0.4.1 lib/interaction/result_creation.rb
aleph_analytics-0.3.0 lib/interaction/result_creation.rb
aleph_analytics-0.2.0 lib/interaction/result_creation.rb
aleph_analytics-0.1.0 lib/interaction/result_creation.rb
aleph_analytics-0.0.6 lib/interaction/result_creation.rb
aleph_analytics-0.0.5 lib/interaction/result_creation.rb
aleph_analytics-0.0.4 lib/interaction/result_creation.rb
aleph_analytics-0.0.3 lib/interaction/result_creation.rb
aleph_analytics-0.0.2 lib/interaction/result_creation.rb
aleph_analytics-0.0.1.alpha lib/interaction/result_creation.rb
aleph_analytics-0.0.0.alpha lib/interaction/result_creation.rb