Sha256: 8f8c45d7384760d896091f5f4d069b08df3e4ca623b616b2f496281139c5d33b

Contents?: true

Size: 779 Bytes

Versions: 1

Compression:

Stored size: 779 Bytes

Contents

module Solder
  class UiStateController < ApplicationController
    before_action :set_ui_state, only: :show
    around_action Solder.config[:around_action]

    def show
      render json: @ui_state.to_json
    end

    def update
      Rails.cache.write "solder/#{ui_state_params[:key]}", parsed_attributes
      records_to_touch.map(&:touch)

      head :ok
    end

    private

    def ui_state_params
      params.permit(:attributes, :key)
    end

    def set_ui_state
      @ui_state = Rails.cache.read "solder/#{ui_state_params[:key]}"
    end

    def records_to_touch
      GlobalID::Locator.locate_many_signed parsed_attributes["data-solder-touch"]&.split(":") || []
    end

    def parsed_attributes
      JSON.parse(ui_state_params[:attributes])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
solder-0.2.0 app/controllers/solder/ui_state_controller.rb