arjad_version_tracker 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbf705d7171dc9d343910f893066c4f821f1a9cf6e101544fa339a405b0425c4
4
- data.tar.gz: b5a6cbf1dfe3dc1444a619fce5e4ab3fb05f1a20b9f88be2f8d25c381d99271b
3
+ metadata.gz: 50ecc931913317e56468037e60050505ccb703680308faddc98f61d16e61613d
4
+ data.tar.gz: 41fc5f34942f6526f52756a6b0e623c87e4ee7a43ed3ad73da5c52b0d383c454
5
5
  SHA512:
6
- metadata.gz: ec1f79121f31b5c4a8f457a4b812a9187308236ce7b727e26d7dc00855fccf321cd5a20f9a07e9ce709bb0ad1beec1b7d6fed7cb60269206397f14601c90e982
7
- data.tar.gz: 176cc8d39d9d1ee2a01c3e8bd2bb84e50e2292bad5e06b8ce63f347ecac599a7cc322e1f308221f2e7782baa4255789ccc1b85186f2dd11bb3ccb9b5f83a9120
6
+ metadata.gz: 626c9a2eac014830c608ae6dbfa3f925034ecbf2f7aec0c23d4d0ae1c41e85bcb40fc5b054596d951c13718dd16dd47c3390b4f059830ae451f17e6cda464ec9
7
+ data.tar.gz: fdb1c753bdeefc539e1aeef0c73c4a0cda677deb3302967eb580aba8d99d0d6a41dcc0cc6243f6d7752607b3ed2dba1c626b83319470e60b163dcd3f955609da
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require_relative "lib/arjad_version_tracker/version"
4
2
 
5
3
  Gem::Specification.new do |spec|
@@ -7,8 +5,8 @@ Gem::Specification.new do |spec|
7
5
  spec.version = ArjadVersionTracker::VERSION
8
6
  spec.authors = ["arjad"]
9
7
  spec.email = ["arjadgohar14@gmail.com"]
10
- spec.summary = "Gem to track and manage version history of models in Rails applications."
11
- spec.description = "Arjad Version Tracker is a Ruby gem designed to simplify tracking and managing version history of models in Rails applications. It provides a straightforward interface for creating, updating, and retrieving historical versions of model records, allowing developers to implement versioning functionality with ease."
8
+ spec.summary = "Gem to get the last state of models in Rails applications."
9
+ spec.description = "Arjad Version Tracker is a Ruby gem designed to simplify manage version history of models in Rails applications. It provides a last versions of model records, allowing developers to implement versioning functionality with ease."
12
10
  spec.homepage = "https://github.com/arjad/arjad_version_tracker"
13
11
  spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
14
12
 
@@ -17,21 +15,14 @@ Gem::Specification.new do |spec|
17
15
  spec.metadata["source_code_uri"] = "https://github.com/arjad/version_tracker"
18
16
  spec.metadata["changelog_uri"] = "https://github.com/arjad/version_tracker/blob/main/CHANGELOG.md"
19
17
 
20
- # Specify which files should be added to the gem when it is released.
21
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
18
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
19
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
24
20
  end
25
- spec.files += Dir["lib/**/*.rb"] # Add this line to include all .rb files in the lib directory
26
- spec.files += Dir["lib/templates/**/*.rb"] # Add this line to include all .rb files in the lib/templates directory
21
+ spec.files += Dir["lib/**/*.rb"]
22
+ spec.files += Dir["lib/templates/**/*.rb"]
27
23
 
28
24
  spec.bindir = "exe"
29
25
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
26
  spec.require_paths = ["lib"]
31
27
 
32
- # Uncomment to register a new dependency of your gem
33
- # spec.add_dependency "example-gem", "~> 1.0"
34
-
35
- # For more information and examples about making a new gem, checkout our
36
- # guide at: https://bundler.io/guides/creating_gem.html
37
28
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ArjadVersionTracker
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
@@ -2,19 +2,12 @@ require "active_record"
2
2
 
3
3
  module ArjadVersionTracker
4
4
  extend ActiveSupport::Concern
5
-
6
5
  included do
7
- has_many :versions, dependent: :destroy
8
6
  before_update :track_version
9
7
  end
10
8
 
11
- def last_version
12
- versions.order(created_at: :desc).first
13
- end
14
-
15
9
  private
16
-
17
10
  def track_version
18
- versions.create!(versionable_id: self.id, versionable_name: self.class.name, data: attributes.except("id", "created_at", "updated_at"))
11
+ self.previous_version = self.changes.except(:updated_at).to_json
19
12
  end
20
13
  end
@@ -1,19 +1,31 @@
1
- # lib/generators/arjad_version_tracker/install_generator.rb
2
-
3
1
  require 'rails/generators/base'
2
+ require 'rails/generators/migration'
4
3
 
5
4
  module ArjadVersionTracker
6
5
  module Generators
7
6
  class InstallGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
8
8
  source_root File.expand_path('templates', __dir__)
9
9
 
10
+ argument :migration_name, type: :string, default: "add_previous_version_to_table"
11
+
10
12
  def create_migration
11
- migration_template 'migration.rb', "db/migrate/#{timestamp}_create_versions.rb"
13
+ migration_template 'migration.rb', "db/migrate/#{migration_timestamp}_#{migration_file_name}.rb"
12
14
  end
13
15
 
14
16
  def self.next_migration_number(dir)
15
17
  Time.now.utc.strftime("%Y%m%d%H%M%S")
16
18
  end
19
+
20
+ private
21
+
22
+ def migration_timestamp
23
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
24
+ end
25
+
26
+ def migration_file_name
27
+ migration_name.underscore
28
+ end
17
29
  end
18
30
  end
19
31
  end
metadata CHANGED
@@ -1,18 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arjad_version_tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - arjad
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-25 00:00:00.000000000 Z
11
+ date: 2024-05-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Arjad Version Tracker is a Ruby gem designed to simplify tracking and
14
- managing version history of models in Rails applications. It provides a straightforward
15
- interface for creating, updating, and retrieving historical versions of model records,
13
+ description: Arjad Version Tracker is a Ruby gem designed to simplify manage version
14
+ history of models in Rails applications. It provides a last versions of model records,
16
15
  allowing developers to implement versioning functionality with ease.
17
16
  email:
18
17
  - arjadgohar14@gmail.com
@@ -31,7 +30,6 @@ files:
31
30
  - lib/arjad_version_tracker.rb
32
31
  - lib/arjad_version_tracker/version.rb
33
32
  - lib/generators/arjad_version_tracker/install_generator.rb
34
- - lib/generators/arjad_version_tracker/templates/migration.rb
35
33
  homepage: https://github.com/arjad/arjad_version_tracker
36
34
  licenses: []
37
35
  metadata:
@@ -57,5 +55,5 @@ requirements: []
57
55
  rubygems_version: 3.2.3
58
56
  signing_key:
59
57
  specification_version: 4
60
- summary: Gem to track and manage version history of models in Rails applications.
58
+ summary: Gem to get the last state of models in Rails applications.
61
59
  test_files: []
@@ -1,12 +0,0 @@
1
- # lib/generators/arjad_version_tracker/templates/migration.rb
2
- class CreateVersions < ActiveRecord::Migration[6.0]
3
- def change
4
- create_table :versions do |t|
5
- # Add necessary fields here to store the version data
6
- t.jsonb :data
7
- t.string :versionable_name
8
- t.integer :versionable_id
9
- t.timestamps
10
- end
11
- end
12
- end