Sha256: 9641d9a5cc56803c5416d0cd8b0c33044ed678da1a9bdf1a0753cabf31fd76f7

Contents?: true

Size: 1.47 KB

Versions: 7

Compression:

Stored size: 1.47 KB

Contents

# frozen_string_literal: true

# ActionsOnDatabase Module
module KepplerFrontend
  module Concerns
    module CallbackActions
      extend ActiveSupport::Concern


      def url_front
        "#{Rails.root}/rockets/keppler_frontend"
      end

      #[:belongs_to, :has_one, :has_many, :has_and_belongs_to_many]
      def callback_line(view, callback)
        callback_list = {
          :before_action => "before_action :#{callback[:name]}, only: [:#{view.name}]",
          :before_filter => "before_filter :#{callback[:name]}, only: [:#{view.name}]",
          :after_action => "after_action :#{callback[:name]}, only: [:#{view.name}]",
          :after_filter => "after_filter :#{callback[:name]}, only: [:#{view.name}]"
        }
        callback_list[callback[:function_type].to_sym]
      end

      def search_callback_line(view, callback)
        file = "#{url_front}/app/controllers/keppler_frontend/app/frontend_controller.rb"
        code = File.readlines(file)
        line = "    #{callback_line(view, callback)}\n"
        result = code.include?(line) ? code.find_index(line) : 0
      end

      def delete_callback(view, callback)
        file = "#{url_front}/app/controllers/keppler_frontend/app/frontend_controller.rb"
        callback_index = search_callback_line(view, callback)
        code = File.readlines(file)
        if callback_index > 0
          code.delete_at(callback_index)
        end
        code = code.join('')
        File.write(file, code)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
keppler-2.1.22 installer/core/rockets/keppler_frontend/app/models/keppler_frontend/concerns/callback_actions.rb
keppler-2.1.21 installer/core/rockets/keppler_frontend/app/models/keppler_frontend/concerns/callback_actions.rb
keppler-2.1.20 installer/core/rockets/keppler_frontend/app/models/keppler_frontend/concerns/callback_actions.rb
keppler-2.1.19 installer/core/rockets/keppler_frontend/app/models/keppler_frontend/concerns/callback_actions.rb
keppler-2.1.18 installer/core/rockets/keppler_frontend/app/models/keppler_frontend/concerns/callback_actions.rb
keppler-2.1.17 installer/core/rockets/keppler_frontend/app/models/keppler_frontend/concerns/callback_actions.rb
keppler-2.1.16 installer/core/rockets/keppler_frontend/app/models/keppler_frontend/concerns/callback_actions.rb