Sha256: bd0a198edc7ce137e98caac35b3f98a58b42077a3eb45239c64bd44b355b8f13

Contents?: true

Size: 1.28 KB

Versions: 8

Compression:

Stored size: 1.28 KB

Contents

require 'reactive_record/server_data_cache'

module ReactiveRecord

  class ReactiveRecordController < ::ApplicationController

    def fetch
      render :json => ReactiveRecord::ServerDataCache[
        (json_params[:models] || []).map(&:with_indifferent_access),
        (json_params[:associations] || []).map(&:with_indifferent_access),
        json_params[:pending_fetches],
        acting_user
      ]
    rescue Exception => e
      render json: {error: e.message, backtrace: e.backtrace}, status: 500
    end

    def save
      render :json => ReactiveRecord::Base.save_records(
        (json_params[:models] || []).map(&:with_indifferent_access),
        (json_params[:associations] || []).map(&:with_indifferent_access),
        acting_user,
        json_params[:validate],
        true
      )
    rescue Exception => e
      render json: {error: e.message, backtrace: e.backtrace}, status: 500
    end

    def destroy
      render :json => ReactiveRecord::Base.destroy_record(
        json_params[:model],
        json_params[:id],
        json_params[:vector],
        acting_user
      )
    rescue Exception => e
      render json: {error: e.message, backtrace: e.backtrace}, status: 500
    end

    private

    def json_params
      JSON.parse(params[:json]).symbolize_keys
    end

  end

end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
hyper-mesh-0.5.3 app/controllers/reactive_record/reactive_record_controller.rb
hyper-mesh-0.5.2 app/controllers/reactive_record/reactive_record_controller.rb
hyper-mesh-0.5.1 app/controllers/reactive_record/reactive_record_controller.rb
hyper-mesh-0.5.0 app/controllers/reactive_record/reactive_record_controller.rb
hyper-mesh-0.4.0 app/controllers/reactive_record/reactive_record_controller.rb
reactive-record-0.8.3 app/controllers/reactive_record/reactive_record_controller.rb
reactive-record-0.8.2 app/controllers/reactive_record/reactive_record_controller.rb
reactive-record-0.8.1 app/controllers/reactive_record/reactive_record_controller.rb