Giter Site home page Giter Site logo

logisticed's Introduction

Logisticed

中文文档

Easily record the operation time and operator for each record's status change.

Installation

Add this line to your application's Gemfile:

gem 'logisticed'

Then, from your Rails app directory, create the logistics table:

$ rake logisticed_migration:install:migrations
$ rails db:migrate

Usage

You only need to tell logisticed which field to listen to and when it is changed to what value.

It will provide you with several methods like active_at, active_by, archived_at, archived_by, giving you the recent operation history for a specific status.

class Page < ActiveRecord::Base
  logisticed :status, values: [:active, :archived]
end

If you've defined an enum type field in the model, you can directly add logisticed below the enum definition. It will automatically listen to all values of the enum.

class Page < ActiveRecord::Base
  enum status: [:draft, :active, :archived]
  logisticed :status
end

At the same time, logisticed supports the only and except parameters.

class Page < ActiveRecord::Base
  enum status: [:draft, :active, :archived]
  logisticed :status, only: [:active, :archived]
end

Now you can listen to all the information about operators and operation time.

class PagesController < ApplicationController
  def create
    current_user # => #<User name: 'sss'>
    @page = Page.first # => #<Page status: 'draft'>
    @page.active!
    @page.active_at # => 2021-01-22 17:15:13 +0800
    @page.active_by # => #<User name: 'sss'>
  end
end

You can use @page.logistics to get all change processes for the record, or use @page.active_logistics to get all change processes when the status becomes active.

In addition, you can use as_user to specify a user as an operator.

class PagesController < ApplicationController
  def create
    current_user # => #<User name: 'sss'>
    user = User.last # => #<User name: 'smx'>
    Logisticed::Logistic.as_user(user) do
      @page = Page.first # => #<Page status: 'draft'>
      @page.active!
      @page.active_at # => 2021-01-22 17:15:13 +0800
      @page.active_by # => #<User name: 'smx'>
    end
  end
end

setting

# config/initializers/logisticed.rb

Logisticed.config do |config|
  config.current_user_method                = :authenticated_user
  # if your table primary_key type is uuid
  config.logisticed_source_id_column_type   = :uuid
  config.logisticed_operator_id_column_type = :uuid
end

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.