Sha256: c9fe297fec0aef6445af8e8ceab180ac900c30cc9eadb0bc0295de49767da7ee

Contents?: true

Size: 1.14 KB

Versions: 6

Compression:

Stored size: 1.14 KB

Contents

module SettingConcern
  extend ActiveSupport::Concern

  included do
    before_action :login_required
    before_action :find_fluentd
    helper_method :target_plugin_name, :plugin_setting_form_action_url
  end


  def show
    @setting = target_class.new(initial_params)
    render "shared/settings/show"
  end

  def finish
    @setting = target_class.new(setting_params)
    unless @setting.valid?
      return render "shared/settings/show"
    end

    @fluentd.agent.config_append @setting.to_config
    if @fluentd.agent.running?
      unless @fluentd.agent.restart
        @setting.errors.add(:base, @fluentd.agent.log_tail(1).first)
        return render "shared/settings/show"
      end
    end
    redirect_to daemon_setting_path(@fluentd)
  end

  private

  def setting_params
    params.require(target_class.to_s.underscore.gsub("/", "_")).permit(*target_class.const_get(:KEYS))
  end

  def initial_params
    target_class.initial_params
  end

  def target_plugin_name
    target_class.to_s.split("::").last.underscore
  end

  def plugin_setting_form_action_url(*args)
    send("finish_daemon_setting_#{target_plugin_name}_path", *args)
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fluentd-ui-0.3.14 app/controllers/concerns/setting_concern.rb
fluentd-ui-0.3.13 app/controllers/concerns/setting_concern.rb
fluentd-ui-0.3.12 app/controllers/concerns/setting_concern.rb
fluentd-ui-0.3.11 app/controllers/concerns/setting_concern.rb
fluentd-ui-0.3.10 app/controllers/concerns/setting_concern.rb
fluentd-ui-0.3.9 app/controllers/concerns/setting_concern.rb