Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add label option #127

Merged
merged 2 commits into from
Mar 2, 2023
Merged

add label option #127

merged 2 commits into from
Mar 2, 2023

Conversation

QWYNG
Copy link
Contributor

@QWYNG QWYNG commented Feb 28, 2023

Thank you for great gem!
This is a proposal and pull request at once.

Summary

Added option to display labels in ActiveRecord::Bitemporal::Visualizer

Sample code

# frozen_string_literal: true

require 'bundler/inline'

gemfile(true) do
  source 'https://rubygems.org'

  git_source(:github) { |repo| "https://github.com/#{repo}.git" }

  gem 'rails', '7.0.1'
  gem 'activerecord-bitemporal', path: '../activerecord-bitemporal'
  gem 'sqlite3'
  gem 'timecop'
end

require 'active_record'
require 'active_support/all'
require 'activerecord-bitemporal'

ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')

ActiveRecord::Schema.define do
  create_table :companies, force: true do |t|
    t.integer :bitemporal_id

    t.string :name

    t.datetime :valid_from, precision: 6
    t.datetime :valid_to, precision: 6
    t.datetime :deleted_at, precision: 6
    t.datetime :transaction_from, precision: 6
    t.datetime :transaction_to, precision: 6

    t.timestamps
  end
end

Time.zone = 'UTC'

class Company < ActiveRecord::Base
  include ActiveRecord::Bitemporal
end

company = nil
Timecop.freeze('2023-02-28') do
  ActiveRecord::Bitemporal.valid_at('2000/01/01') do
    company = Company.create!(name: 'A')
  end
end

Timecop.freeze('2023-03-1') do
  ActiveRecord::Bitemporal.valid_at('2020/07/01') do
    company.reload.update!(name: 'C')
  end
end

puts ActiveRecord::Bitemporal::Visualizer.visualize(company, label: true)

output

 > ruby test.rb
Fetching gem metadata from https://rubygems.org/...........
~~ snip ~~
transaction_datetime    | valid_datetime
                        | 2000-01-01 00:00:00.000
                        |                   | 2020-07-01 00:00:00.000
                        |                   |                   | 9999-12-31 00:00:00.000
2023-02-28 00:00:00.000 +---------------------------------------+
                        |                                       |
                        |                                       |
                        |                                       |
                        |                                       |
2023-03-01 00:00:00.000 +-------------------+-------------------+
                        |                   |*******************|
                        |                   |*******************|
                        |                   |*******************|
                        |                   |*******************|
9999-12-31 00:00:00.000 +-------------------+-------------------+

@QWYNG QWYNG marked this pull request as ready for review February 28, 2023 10:02
@auto-assign auto-assign bot requested review from lighty and wata727 February 28, 2023 10:02
@osyo-manga
Copy link
Collaborator

osyo-manga commented Mar 1, 2023

@QWYNG Thanks! Great!
I think it would be better if it is output by default rather than optional, since it does not affect the functionality and it would be preferable to have it by default.

@QWYNG
Copy link
Contributor Author

QWYNG commented Mar 1, 2023

@osyo-manga
thank you!
Changed to output labels by default

Copy link
Collaborator

@osyo-manga osyo-manga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@QWYNG OK, Thanks!

@QWYNG QWYNG merged commit 7fc18fe into kufu:master Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants