<commit_before>class DeviceScriptsController < ApplicationController

  include SortableController

  load_and_authorize_resource

  inject :device_script_manager

  def index
    @device_scripts = DeviceScript.search(params[:q]).order("#{sort_column} #{sort_order}").page(params[:page])
  end

  def create
    @device_script = DeviceScript.new device_script_params
    if @device_script.save
      device_script_manager.update_script @device_script
      render status: :ok, nothing: true
    else
      render status: :bad_request, json: { errors: @device_script.errors }
    end
  end

  def show
  end

  def update
    if @device_script.update_attributes device_script_params
      device_script_manager.update_script @device_script
      render status: :ok, nothing: true
    else
      render status: :bad_request, json: { errors: @device_script.errors }
    end
  end

  def destroy
    @device_script = DeviceScript.find params[:id]
    @device_script.destroy
    render status: :ok, nothing: true
  end

  def enable
    @device_script = DeviceScript.find params[:id]
    @device_script.update_attribute :enabled, true
    render status: :ok, nothing: true
  end

  def disable
    @device_script = DeviceScript.find params[:id]
    @device_script.update_attribute :enabled, false
    render status: :ok, nothing: true
  end

  private
  def device_script_params
    json_params = ActionController::Parameters.new JSON.parse request.body.read
    json_params.permit :id, :name, :description, :script, :enabled
  end

  private
  def default_sort_column
    :name
  end

end
<commit_msg>fix: Device script is not stopped/started when the enable attribute was modified<commit_after>class DeviceScriptsController < ApplicationController

  include SortableController

  load_and_authorize_resource

  inject :device_script_manager

  def index
    @device_scripts = DeviceScript.search(params[:q]).order("#{sort_column} #{sort_order}").page(params[:page])
  end

  def create
    @device_script = DeviceScript.new device_script_params
    if @device_script.save
      device_script_manager.update_script @device_script
      render status: :ok, nothing: true
    else
      render status: :bad_request, json: { errors: @device_script.errors }
    end
  end

  def show
  end

  def update
    if @device_script.update_attributes device_script_params
      device_script_manager.update_script @device_script
      render status: :ok, nothing: true
    else
      render status: :bad_request, json: { errors: @device_script.errors }
    end
  end

  def destroy
    @device_script = DeviceScript.find params[:id]
    @device_script.destroy
    render status: :ok, nothing: true
  end

  def enable
    @device_script = DeviceScript.find params[:id]
    @device_script.update_attribute :enabled, true
    device_script_manager.update_script @device_script
    render status: :ok, nothing: true
  end

  def disable
    @device_script = DeviceScript.find params[:id]
    @device_script.update_attribute :enabled, false
    device_script_manager.update_script @device_script
    render status: :ok, nothing: true
  end

  private
  def device_script_params
    json_params = ActionController::Parameters.new JSON.parse request.body.read
    json_params.permit :id, :name, :description, :script, :enabled
  end

  private
  def default_sort_column
    :name
  end

end

{'fraction_non_alphanumeric': 0.07594185701572234, 'fraction_numerical': 0.0, 'mean_word_length': 3.937042459736457, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7477032', 'n_tokens_mistral': 1002, 'n_tokens_neox': 976, 'n_words': 257}