Rails Execution

Rails Execution is an Engine to manage the Rails scripts for migration, cleanup, and fixing the bad data without deployment.

  • Supported the Syntax checker
  • Supported the Execution logs
  • Supported the Reviewing process
  • Supported the Attachment files
  • Supported the Comments communication
  • Supported the Activities tracking

image image

Installation

Add the following line to your Gemfile:

gem 'rails_execution'

Then run bundle install

Getting started

How to setup

You need to run the generator:

    $ rails g rails_execution:install

And you can change the config in config/initializers/rails_execution.rb

Default is Solo Mode, without the Reviewing process.

Enable the Reviewing process

The first step is to disable the Solo Mode

    config.solo_mode = false

And then uncomment the configures of the owner and reviewers

    config.owner_model = 'User'
    config.owner_method = :current_user
    config.owner_name_method = :name
    config.owner_avatar = ->(owner) { owner.avatar.url }

    config.reviewers = -> do
      User.where(is_admin: true).map do |user|
        {
          name: user.name,
          id: user.id,
          type: 'User',
          avatar_url: user.avatar.url,
        }
      end
    end

Enable the Attachment files

Run the generator to add the FileUploader and FileReader

    $ rails g rails_execution:file_upload

And then uncomment the file upload

  config.file_upload = true
  config.file_uploader = ::RailsExecution::FileUploader
  config.file_reader = ::RailsExecution::FileReader

To limit the File types. Default: .png, .gif, .jpg, .jpeg, .pdf, .csv You can modify the limitation like this

  config.acceptable_file_types = {
    '.jpeg': 'image/jpeg',
    '.pdf': 'application/pdf',
    '.csv': ['text/csv', 'text/plain'],
  }

Control the Permissions

For example with Pundit authorization.

  config.task_creatable = lambda do |user|
    YourPolicy.new(user).creatable?
  end
  config.task_editable = lambda do |task, user|
    YourPolicy.new(user, task).editable?
  end
  config.task_closable = lambda do |task, user|
    YourPolicy.new(user, task).closable?
  end
  config.task_approvable = lambda do |task, user|
    YourPolicy.new(user, task).approvable?
  end
  config.task_executable = lambda do |task, user|
    YourPolicy.new(user, task).executable?
  end

Setup the Logger

To storage the logfile

  config.logging = lambda do |file, task|
    LoggerModel.create!(task: task, file: file)
  end

And list the logfiles on Task page

  config.logging_files = lambda do |task|
    LoggerModel.where(task: task).map do |log|
      log.file.expiring_url(30.minutes.to_i)
    end
  end

Others

To change the Per page of the tasks list. Default value: 20

  config.per_page = 10