Skip to content

Commit

Permalink
Rename the gem to camel_trail (#130)
Browse files Browse the repository at this point in the history
This PR renames the simple_trail to camel_trail. Apparently,
simple_trail name gem was used for a gem which is yanked and we can't
use it.
  • Loading branch information
ghaydarov authored Mar 21, 2023
1 parent c398294 commit 1409e16
Show file tree
Hide file tree
Showing 59 changed files with 165 additions and 165 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: simple_trail
name: camel_trail

on:
push:
Expand Down
4 changes: 2 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ A shared layout so that your suite of applications can have the same look and fe

Edgestitch allows engines to define partial structure-self.sql files to be stitched into a single structure.sql file by the umbrella application.

[simple_trail](https://github.com/powerhome/power-tools/blob/main/packages/simple_trail/docs/README.md) 💎
[camel_trail](https://github.com/powerhome/power-tools/blob/main/packages/camel_trail/docs/README.md) 💎

SimpleTrail makes it easy to keep a history of attribute changes on a model.
CamelTrail makes it easy to keep a history of attribute changes on a model.

## Installation 🛠

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Gemfile.lock
*.DS_Store
doc/*
!doc/dependency_decisions.yml
spec/dummy/db/simple_trail_test.sqlite
spec/dummy/db/simple_trail_development.sqlite
db/simple_trail_test.sqlite
db/simple_trail_development.sqlite
spec/dummy/db/camel_trail_test.sqlite
spec/dummy/db/camel_trail_development.sqlite
db/camel_trail_test.sqlite
db/camel_trail_development.sqlite
spec/dummy/log/test.log
spec/dummy/log/development.log
spec/dummy/db/structure.sql
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

source "https://rubygems.org"

# Declare your gem's dependencies in simple_trail.gemspec.
# Declare your gem's dependencies in camel_trail.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ begin
require "yard"
YARD::Rake::YardocTask.new do |t|
t.files = ["lib/**/*.rb"]
t.files = ["app/models/simple_trail/*.rb"]
t.files = ["app/models/camel_trail/*.rb"]
end
rescue LoadError
puts "You must `bundle install` to run rake tasks"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module SimpleTrail
module CamelTrail
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module SimpleTrail
class EncryptedHistory < ::SimpleTrail::History
module CamelTrail
class EncryptedHistory < ::CamelTrail::History
extend AttrEncrypted

attr_encrypted :note, key: NitroConfig.get_deferred!("encryption_key"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

module SimpleTrail
class History < ::SimpleTrail::ApplicationRecord
serialize :source_changes, ::SimpleTrail::YAMLUnsafeCoder
module CamelTrail
class History < ::CamelTrail::ApplicationRecord
serialize :source_changes, ::CamelTrail::YAMLUnsafeCoder
serialize :backtrace, Array

default_scope { order("id DESC") }
Expand All @@ -18,7 +18,7 @@ class History < ::SimpleTrail::ApplicationRecord
private

def set_backtrace
self.backtrace = SimpleTrail::Config.backtrace_cleaner&.clean(caller) || caller
self.backtrace = CamelTrail::Config.backtrace_cleaner&.clean(caller) || caller
end
end
end
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "simple_trail/version"
require "camel_trail/version"

Gem::Specification.new do |s|
s.name = "simple_trail"
s.version = SimpleTrail::VERSION
s.name = "camel_trail"
s.version = CamelTrail::VERSION
s.authors = ["Gurban Haydarov"]
s.email = ["[email protected]"]
s.summary = "Simple way to track database changes"
s.description = "SimpleTrail makes it easy to keep a history of attribute changes on a model"
s.description = "CamelTrail makes it easy to keep a history of attribute changes on a model"

s.homepage = "https://github.com/powerhome/power-tools"
s.license = "MIT"
Expand Down
7 changes: 7 additions & 0 deletions packages/camel_trail/config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
development:
adapter: sqlite3
database: db/camel_trail_development.sqlite

test:
adapter: sqlite3
database: db/camel_trail_test.sqlite
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

# rubocop:disable Metrics/MethodLength
class CreateSimpleTrails < ActiveRecord::Migration[6.0]
class CreateCamelTrails < ActiveRecord::Migration[6.0]
def change
create_table :"#{SimpleTrail.table_name_prefix}histories" do |t|
create_table :"#{CamelTrail.table_name_prefix}histories" do |t|
t.string :source_type
t.string :source_id
t.text :source_changes
Expand All @@ -14,7 +14,7 @@ def change
t.text :backtrace
end

add_index :"#{SimpleTrail.table_name_prefix}histories", %i[source_type source_id]
add_index :"#{CamelTrail.table_name_prefix}histories", %i[source_type source_id]
end
end
# rubocop:enable Metrics/MethodLength
6 changes: 6 additions & 0 deletions packages/camel_trail/docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## [Unreleased]

## [0.0.1] - 2023-03-20

- Extracts NitroHistory main functionality into CamelTrail

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
## What is SimpleTrail
## What is CamelTrail

SimpleTrail makes it easy to keep a history of attribute changes on a model
CamelTrail makes it easy to keep a history of attribute changes on a model

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'simple_trail'
gem 'camel_trail'
```

And then execute:
Expand All @@ -16,18 +16,18 @@ And then execute:

Or install it yourself as:

$ gem install simple_trail
$ gem install camel_trail


# Configuration

1. Add SimpleTrail config to your initializer file.
2. You need to set `current_session_user_id` to include user info in `simple_trail_histories` table.
3. You can optionally set `table_name_prefix` to customize default table name. Defaults to `simple_trail_histories`.
4. SimpleTrail stores backtrace info in `simple_trail_histories`. It defaults to `Rails.backtrace_cleaner`. You can optionally set it to your customized backtrace cleaner.
1. Add CamelTrail config to your initializer file.
2. You need to set `current_session_user_id` to include user info in `camel_trail_histories` table.
3. You can optionally set `table_name_prefix` to customize default table name. Defaults to `camel_trail_histories`.
4. CamelTrail stores backtrace info in `camel_trail_histories`. It defaults to `Rails.backtrace_cleaner`. You can optionally set it to your customized backtrace cleaner.

```ruby
SimpleTrail.config do
CamelTrail.config do
table_name_prefix "myapp_"
current_session_user_id { MyApp.current_session_user_id }
backtrace_cleaner { YourCustom.backtrace_cleaner }
Expand All @@ -38,22 +38,22 @@ end

```ruby
class Project < ApplicationRecord
  include ::SimpleTrail::Recordable
  include ::CamelTrail::Recordable
end
```

Inlcude `simple_trail` in your lib files if you need to call it there:
Inlcude `camel_trail` in your lib files if you need to call it there:

```ruby
require "simple_trail"
require "camel_trail"
```


Now you can access the object history through `SimpleTrail.for(object)` like:
Now you can access the object history through `CamelTrail.for(object)` like:

```ruby
project = Project.create
SimpleTrail.for(project).size
CamelTrail.for(project).size
# => 1
```

Expand All @@ -62,7 +62,7 @@ The user performing the action will be recorded from the Thread local `:user_id`
Then, require the engine in your `application.rb`

```ruby
require "simple_trail"
require "camel_trail"
```

## Contributing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

require "attr_encrypted"
require "nitro_config"
require "simple_trail/engine"
require "simple_trail/entry_presenter"
require "simple_trail/recordable"
require "simple_trail/yaml_unsafe_coder"
require "simple_trail/config"
require "camel_trail/engine"
require "camel_trail/entry_presenter"
require "camel_trail/recordable"
require "camel_trail/yaml_unsafe_coder"
require "camel_trail/config"

module SimpleTrail
module CamelTrail
module_function

mattr_accessor(:table_name_prefix) { "simple_trail_" }
mattr_accessor(:table_name_prefix) { "camel_trail_" }

# Allows to set configurion for SimpleTrail
# Allows to set configurion for CamelTrail
#
# SimpleTrail.config do
# CamelTrail.config do
# configs to be set
# end
def config(...)
Expand All @@ -30,11 +30,11 @@ def config(...)
# @param user_id [Integer] the id of the user triggered the history entry
# @param note [String] a note that can be attached to a history
# @param encrypted [Boolean] whether to encrypt or not the note
# @return [SimpleTrail::EntryPresenter]
# @return [CamelTrail::EntryPresenter]

# rubocop:disable Metrics/ParameterLists
def record!(object, activity, changes, user_id, note = nil, encrypted: false)
klass = encrypted ? SimpleTrail::EncryptedHistory : SimpleTrail::History
klass = encrypted ? CamelTrail::EncryptedHistory : CamelTrail::History

history = klass.for_source(object).create!(
source_changes: changes,
Expand All @@ -49,13 +49,13 @@ def record!(object, activity, changes, user_id, note = nil, encrypted: false)
# A collection of the history entries associated with the object
#
# @param object [#id] the object recording a history
# @return [Array<SimpleTrail::EntryPresenter>]
# @return [Array<CamelTrail::EntryPresenter>]
def for(object, encrypted: false, in_natural_order: false)
klass = encrypted ? SimpleTrail::EncryptedHistory : SimpleTrail::History
klass = encrypted ? CamelTrail::EncryptedHistory : CamelTrail::History

history_collection = in_natural_order ? klass.for_source(object).in_natural_order : klass.for_source(object)
history_collection.to_a.map do |history|
SimpleTrail::EntryPresenter.new(history)
CamelTrail::EntryPresenter.new(history)
end
end
end
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
# frozen_string_literal: true

module SimpleTrail
module CamelTrail
module Config
module_function

# SimpleTrail Stores backtrace info in `simple_trail_histories`
# CamelTrail Stores backtrace info in `camel_trail_histories`
# It's config defaults to `Rails.backtrace_cleaner`
# You can optionally set it to your customized backtrace cleaner
# via `SimpleTrail.config.backtrace_cleaner = MyBacktraceCleaner`
# via `CamelTrail.config.backtrace_cleaner = MyBacktraceCleaner`
mattr_accessor :backtrace_cleaner

# Allows to set configurion for SimpleTrail
# Allows to set configurion for CamelTrail
def config(&block)
class_eval(&block)
end

# Optionally set `table_name_prefix` to customize default table name.
# Defaults to `simple_trail_histories`
# Defaults to `camel_trail_histories`
def table_name_prefix(value)
SimpleTrail.table_name_prefix = value
CamelTrail.table_name_prefix = value
end

# Sets `current_session_user_id` to include user info in `simple_trail_histories` table.
# Sets `current_session_user_id` to include user info in `camel_trail_histories` table.
def current_session_user_id(&block)
@current_session_user_id = block if block
@current_session_user_id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

module SimpleTrail
module CamelTrail
class Engine < ::Rails::Engine
isolate_namespace SimpleTrail
isolate_namespace CamelTrail

config.generators do |g|
g.test_framework :rspec
Expand All @@ -20,8 +20,8 @@ class Engine < ::Rails::Engine
end
end

initializer "simple_trail.backtrace_cleaner" do
SimpleTrail::Config.backtrace_cleaner ||= Rails.backtrace_cleaner
initializer "camel_trail.backtrace_cleaner" do
CamelTrail::Config.backtrace_cleaner ||= Rails.backtrace_cleaner
end
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module SimpleTrail
module CamelTrail
class EntryPresenter
delegate :backtrace,
:created_at,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module SimpleTrail
module CamelTrail
module Recordable
extend ActiveSupport::Concern

Expand All @@ -9,10 +9,10 @@ module Recordable
end

class_methods do
attr_reader :__simple_trail_source_changes
attr_reader :__camel_trail_source_changes

def history_options(source_changes: nil)
@__simple_trail_source_changes = source_changes
@__camel_trail_source_changes = source_changes
end
end

Expand All @@ -21,12 +21,12 @@ def history_options(source_changes: nil)
def __record_changes
activity = new_record? ? :created : :updated
yield
SimpleTrail.record!(self, activity, __simple_trail_source_changes,
SimpleTrail::Config.current_session_user_id&.call)
CamelTrail.record!(self, activity, __camel_trail_source_changes,
CamelTrail::Config.current_session_user_id&.call)
end

def __simple_trail_source_changes
source_changes = self.class.__simple_trail_source_changes
def __camel_trail_source_changes
source_changes = self.class.__camel_trail_source_changes

case source_changes
when Proc then instance_exec(&source_changes)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

module SimpleTrail
module CamelTrail
# The current version of the gem.
VERSION = "0.1.0"
VERSION = "0.0.1"
end
Loading

0 comments on commit 1409e16

Please sign in to comment.