arjad_version_tracker 0.3.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: e4fa3113d74d5358ba7b716b79ec419e9f46922fa954f95228fa1e9fb41fc533
4
- data.tar.gz: 48e35df113a86effbfda007f0f0405709064e8cd54979aac5a48be93c115f9a6
3
+ metadata.gz: 50ecc931913317e56468037e60050505ccb703680308faddc98f61d16e61613d
4
+ data.tar.gz: 41fc5f34942f6526f52756a6b0e623c87e4ee7a43ed3ad73da5c52b0d383c454
5
5
  SHA512:
6
- metadata.gz: bde8dcb9a46640e242cc1a93549c8a87af60489b31069df832fe9e595a26d762305bf69b4dc14118e8adc025a4359b4f92ecff835091335d3bc4dc41078f82c3
7
- data.tar.gz: fe7dd10d9f069c11409a8c3026d8c4463f99af6ea9392a070d6d4555e7ef73020b9a180b80bc2c6adb23d370cef8b671d44e09955615b5820080c150a1a5d6e0
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.3.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!(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,24 +1,30 @@
1
- # lib/generators/arjad_version_tracker/install_generator.rb
2
1
  require 'rails/generators/base'
2
+ require 'rails/generators/migration'
3
3
 
4
4
  module ArjadVersionTracker
5
5
  module Generators
6
6
  class InstallGenerator < Rails::Generators::Base
7
+ include Rails::Generators::Migration
7
8
  source_root File.expand_path('templates', __dir__)
8
9
 
9
- def copy_migration
10
- timestamp = Time.now.utc.strftime('%Y%m%d%H%M%S')
11
- template 'migration.rb', "db/migrate/#{timestamp}_create_#{table_name}_versions.rb"
10
+ argument :migration_name, type: :string, default: "add_previous_version_to_table"
11
+
12
+ def create_migration
13
+ migration_template 'migration.rb', "db/migrate/#{migration_timestamp}_#{migration_file_name}.rb"
14
+ end
15
+
16
+ def self.next_migration_number(dir)
17
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
12
18
  end
13
19
 
14
20
  private
15
21
 
16
- def table_name
17
- model_name.pluralize.underscore
22
+ def migration_timestamp
23
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
18
24
  end
19
25
 
20
- def model_name
21
- self.class.name.sub(/Generator\z/, '').singularize
26
+ def migration_file_name
27
+ migration_name.underscore
22
28
  end
23
29
  end
24
30
  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.3.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-19 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,13 +0,0 @@
1
- # lib/generators/arjad_version_tracker/templates/migration.rb
2
- class Create<%= table_name.capitalize %>Versions < ActiveRecord::Migration[6.0]
3
- def change
4
- create_table :<%= table_name %>_versions do |t|
5
- # Add necessary fields here to store the version data
6
- t.references :<%= table_name.singularize %>, polymorphic: true, null: false
7
- t.jsonb :data
8
-
9
- t.timestamps
10
- end
11
- end
12
- end
13
-