Project

editus

0.0
No release in over a year
This application is a user-friendly web interface designed to work with a Ruby on Rails application. With a simple and intuitive web interface, users can conveniently access the features of the application. One of the key features of this application is the ability to directly edit models. This enables users to make changes directly to the data without the need to learn and use complex tools. Through the web interface, users can access and modify the attributes of models with ease. Additionally, the application provides the capability to run predefined scripts. This allows users to perform automated tasks or handle complex data processing through prebuilt scripts. Running these scripts via the web interface saves users time and effort compared to alternative methods.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 5.0
 Project Readme

Editus

Gem Version

Streamline your coding and database editing processes with Editus. Its intuitive web interface allows you to execute code snippets and perform real-time database modifications with ease.

Table of contents

  • Editus
  • Table of contents
  • Installation
  • Usage
    • Authentication
    • Models
    • Add Script
      • Query
  • Contributing
  • License

Table of contents generated with markdown-toc

Installation

Add this line to your application's Gemfile:

gem "editus"

And then execute:

$ bundle install

Run the following code to create the config file:

rake editus:install # It will create file config/initializer/editus.rb

Add the following to your config/routes.rb:

Rails.application.routes.draw do
  mount Editus::Engine => "/editus" unless Rails.env.production?
  ...
end

Usage

Authentication

Editus supports two forms of authentication:

  1. Define the editus_account method in ApplicationHelper: This method should return the current account (e.g., current_user or current_admin). If this method is defined, Editus will use it to determine the current account.
  module ApplicationHelper
    def editus_account
      current_user # or any other method that returns the current account
    end
  end
  1. Configuration in the config/initializer/editus.rb file: Create an array containing accounts authenticated via HTTP Basic Authentication. Each account is a sub-array with two elements: the username and password.
config.auth = [%w[user@example.com Pass@123456], %w[manager@example.com Pass@123456]]

Use one of the above authentication methods to secure access to Editus. Note that the editus_account method will take precedence if both methods are provided.

Models

Display a simple form interface that helps you update the fields of the selected model. The update will use update_columns so will ignore callback and validate

You can configure to display only the models and fields that you allow:

config.models = ["User", {name: "Admin", fields: %w[name], exclude_fields: %w[id]}]

For the Admin model specified using the fields key. Additionally, the exclude_fields key is used to exclude the id field from being displayed.

Add Script

To execute existing code create a directory config/editus in your code

Example: config/editus/update_nick_name_user.rb

Editus::Script.define :update_nick_name_user do
  title "Update nick_name of user"
  task :up do |id, new_nick_name|
    user = User.find(id)
    old_nick_name = user.nick_name
    user.update_columns nick_name: new_nick_name

    [id, old_nick_name]
  end

  task :down do |id, nick_name|
    User.find(id).update_columns(nick_name: nick_name)
  end
end

Make sure the filename and the defined name are the same. In the above code title to set the title of the code. task :up is the code that will be executed when you run it. task :down is the code that will be executed when you undo, if you don't need to undo you can skip it.

It can use the result returned from the up method to use as an input parameter. The up method can also accept parameters directly.

Query

In addition to running the two tasks up and down, you can perform other small code snippets by using query.

Editus::Script.define :users do
  desc "Number of users"
  query :count_user do
    User.count
  end
end

Contributing

Contribution directions go here.

License

The gem is available as open source under the terms of the MIT License.