gem_activity_tracker 0.1.0 → 0.1.1
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 +4 -4
- data/.gem_activity_tracker.gemspec.swp +0 -0
- data/README.md +171 -16
- data/gem_activity_tracker-0.1.0.gem +0 -0
- data/lib/gem_activity_tracker/railtie.rb +32 -0
- data/lib/gem_activity_tracker/tracker.rb +128 -0
- data/lib/gem_activity_tracker/version.rb +1 -1
- data/lib/gem_activity_tracker/watcher.rb +40 -0
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a4fc1894fed1dbe9dbb47ee25f486ddd4349ded7feb0a4a91384108735dcbec
|
4
|
+
data.tar.gz: 5c56a548d26d058ea64fc09485ce615ca56468c1c8fa886ea47cb37833bf8c68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9e32b18708d76bc93cb247c0ab2a3a536027e8c8ea7b182b3aa585f989b7a3c33fffbc46ebc9c4120c513a8887d60caef4f797e4999920dc32af36e64aeb46d3
|
7
|
+
data.tar.gz: 1c7dd0bd08afba432bd0bdeb3c1d85fea8c4e47e07514f9a976363784c034717e85303f5505ed7f5494cd81f2fbd23406a5129a0067789fd3ad0eea27adf00b6
|
Binary file
|
data/README.md
CHANGED
@@ -1,35 +1,190 @@
|
|
1
|
-
# GemActivityTracker
|
1
|
+
# 🚀 GemActivityTracker
|
2
2
|
|
3
|
-
|
3
|
+
**GemActivityTracker** is a Ruby gem that automatically tracks the structure and changes in your Ruby on Rails project. It collects details like models, controllers, jobs, mailers, services, migrations, schema, routes, and Git history. It also provides real-time file change tracking with a detailed activity log and supports exporting the report as JSON or CSV.
|
4
4
|
|
5
|
-
|
5
|
+
---
|
6
6
|
|
7
|
-
##
|
7
|
+
## 🔍 What Does This Gem Do?
|
8
8
|
|
9
|
-
|
9
|
+
When you include this gem in your Rails project, it will:
|
10
10
|
|
11
|
-
|
11
|
+
- ✅ Scan and record project components:
|
12
|
+
- Models, Controllers, Jobs, Mailers, Services
|
13
|
+
- Migrations, Routes, Schema hash
|
14
|
+
- Database type and Git history
|
15
|
+
- 🔁 Automatically detect changes after initialization
|
16
|
+
- 🕵️ Keep an activity log of every file change (created, modified, removed)
|
17
|
+
- 📊 Export report in:
|
18
|
+
- YAML (default)
|
19
|
+
- JSON
|
20
|
+
- CSV
|
21
|
+
- 🔁 Real-time file watcher using the `listen` gem
|
22
|
+
|
23
|
+
---
|
24
|
+
|
25
|
+
## 🔧 Compatibility
|
26
|
+
|
27
|
+
- ✅ **Ruby**: >= 2.6.5 and < 4.0
|
28
|
+
- ✅ **Rails**: >= 5.2 and <= 7.1
|
29
|
+
|
30
|
+
- ✅ Works with: **MySQL**, **PostgreSQL**, **SQLite**
|
31
|
+
|
32
|
+
---
|
33
|
+
|
34
|
+
## 📦 Installation
|
35
|
+
|
36
|
+
Add this line to your Rails application's Gemfile:
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
gem 'gem_activity_tracker'
|
40
|
+
```
|
41
|
+
|
42
|
+
Then run:
|
12
43
|
|
13
44
|
```bash
|
14
|
-
bundle
|
45
|
+
bundle install
|
15
46
|
```
|
16
47
|
|
17
|
-
|
48
|
+
Or install it manually:
|
18
49
|
|
19
50
|
```bash
|
20
|
-
gem install
|
51
|
+
gem install gem_activity_tracker
|
21
52
|
```
|
22
53
|
|
23
|
-
|
54
|
+
---
|
55
|
+
|
56
|
+
## 🚀 Basic Usage
|
57
|
+
|
58
|
+
Once installed, you can use the CLI commands:
|
59
|
+
|
60
|
+
### 1. 📌 Generate Activity Report
|
61
|
+
|
62
|
+
```bash
|
63
|
+
gem_activity_tracker --track=.
|
64
|
+
```
|
65
|
+
|
66
|
+
It will generate a `report.yml` in the `activity_tracker/` folder.
|
67
|
+
|
68
|
+
---
|
69
|
+
|
70
|
+
### 2. 👁 Start Watching for File Changes
|
71
|
+
|
72
|
+
```bash
|
73
|
+
gem_activity_tracker --watch
|
74
|
+
```
|
75
|
+
|
76
|
+
This will keep watching the project. On any file change (model, controller, migration, etc.), it will:
|
77
|
+
|
78
|
+
- Update the report
|
79
|
+
- Add a new entry to `log.txt`
|
80
|
+
|
81
|
+
---
|
82
|
+
|
83
|
+
### 3. 📄 View Last Generated Report
|
84
|
+
|
85
|
+
```bash
|
86
|
+
gem_activity_tracker --report
|
87
|
+
```
|
88
|
+
|
89
|
+
---
|
90
|
+
|
91
|
+
### 4. 📤 Export Report as JSON
|
92
|
+
|
93
|
+
```bash
|
94
|
+
gem_activity_tracker --export=json
|
95
|
+
```
|
96
|
+
|
97
|
+
---
|
98
|
+
|
99
|
+
### 5. 📤 Export Report as CSV
|
100
|
+
|
101
|
+
```bash
|
102
|
+
gem_activity_tracker --export=csv
|
103
|
+
```
|
104
|
+
|
105
|
+
---
|
106
|
+
|
107
|
+
## 📁 Output Structure
|
108
|
+
|
109
|
+
The following directory is automatically created:
|
110
|
+
|
111
|
+
```
|
112
|
+
activity_tracker/
|
113
|
+
├── report.yml # Main YAML report
|
114
|
+
├── report.json # (Optional) JSON export
|
115
|
+
├── report.csv # (Optional) CSV export
|
116
|
+
└── log.txt # Activity logs of file changes
|
117
|
+
```
|
118
|
+
|
119
|
+
---
|
120
|
+
|
121
|
+
## 🧪 Development
|
122
|
+
|
123
|
+
For contributing or testing locally:
|
124
|
+
|
125
|
+
```bash
|
126
|
+
git clone https://github.com/atul13055/gem_activity_tracker.git
|
127
|
+
cd gem_activity_tracker
|
128
|
+
bundle install
|
129
|
+
```
|
130
|
+
|
131
|
+
Run interactive Ruby console:
|
132
|
+
|
133
|
+
```bash
|
134
|
+
bin/console
|
135
|
+
```
|
136
|
+
|
137
|
+
Build the gem locally:
|
138
|
+
|
139
|
+
```bash
|
140
|
+
bundle exec rake install
|
141
|
+
```
|
142
|
+
|
143
|
+
---
|
144
|
+
|
145
|
+
## 🚀 Releasing New Version
|
146
|
+
|
147
|
+
1. Update version in `lib/gem_activity_tracker/version.rb`
|
148
|
+
2. Build and release:
|
149
|
+
|
150
|
+
```bash
|
151
|
+
bundle exec rake release
|
152
|
+
```
|
153
|
+
|
154
|
+
This will:
|
155
|
+
|
156
|
+
- Create a `.gem` file
|
157
|
+
- Push to RubyGems
|
158
|
+
- Tag and push to GitHub
|
159
|
+
|
160
|
+
---
|
161
|
+
|
162
|
+
## 🤝 Contributing
|
163
|
+
|
164
|
+
1. Fork this repo
|
165
|
+
2. Create a new branch: `git checkout -b my-feature`
|
166
|
+
3. Make your changes
|
167
|
+
4. Commit: `git commit -m "Add my feature"`
|
168
|
+
5. Push: `git push origin my-feature`
|
169
|
+
6. Open a Pull Request
|
170
|
+
|
171
|
+
---
|
172
|
+
|
173
|
+
## 📄 License
|
174
|
+
|
175
|
+
This project is licensed under the [MIT License](https://opensource.org/licenses/MIT).
|
24
176
|
|
25
|
-
|
177
|
+
---
|
26
178
|
|
27
|
-
##
|
179
|
+
## 🌍 Links
|
28
180
|
|
29
|
-
|
181
|
+
- 📦 [RubyGems Page](https://rubygems.org/gems/gem_activity_tracker)
|
182
|
+
- 🧠 [GitHub Repo](https://github.com/atul13055/gem_activity_tracker)
|
30
183
|
|
31
|
-
|
184
|
+
---
|
32
185
|
|
33
|
-
##
|
186
|
+
## 🙌 Author
|
34
187
|
|
35
|
-
|
188
|
+
Built with ❤️ by **Atul Yadav**
|
189
|
+
📧 [atuIyadav9039@gmail.com](mailto:atuIyadav9039@gmail.com)
|
190
|
+
🌐 [LinkedIn](https://www.linkedin.com/in/atul-yadav-9445ab1a4)
|
Binary file
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rails/railtie'
|
2
|
+
|
3
|
+
module GemActivityTracker
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
initializer "gem_activity_tracker.auto_track" do
|
6
|
+
ActiveSupport.on_load(:after_initialize) do
|
7
|
+
Thread.new do
|
8
|
+
begin
|
9
|
+
path = Rails.root.to_s
|
10
|
+
report_path = File.join(path, "activity_tracker", "report.yml")
|
11
|
+
|
12
|
+
last_data = File.exist?(report_path) ? YAML.load_file(report_path) : {}
|
13
|
+
current_data = GemActivityTracker::Tracker.collect_data(path)
|
14
|
+
|
15
|
+
if last_data != current_data
|
16
|
+
puts "🔄 Project activity changed. Updating report..."
|
17
|
+
GemActivityTracker::Tracker.track(path)
|
18
|
+
else
|
19
|
+
puts "✅ No project changes detected."
|
20
|
+
end
|
21
|
+
|
22
|
+
# ✅ Start auto watching
|
23
|
+
puts "👀 Starting auto-watcher for #{path} from Railtie..."
|
24
|
+
GemActivityTracker::Watcher.start(path)
|
25
|
+
rescue => e
|
26
|
+
puts "⚠️ GemActivityTracker error: #{e.message}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'json'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'psych'
|
5
|
+
require 'csv'
|
6
|
+
require 'digest'
|
7
|
+
|
8
|
+
module GemActivityTracker
|
9
|
+
class Tracker
|
10
|
+
def self.track(path)
|
11
|
+
puts "🔍 Tracking project at: #{path}"
|
12
|
+
data = collect_data(path)
|
13
|
+
|
14
|
+
FileUtils.mkdir_p("#{path}/activity_tracker")
|
15
|
+
File.write("#{path}/activity_tracker/report.yml", data.to_yaml)
|
16
|
+
|
17
|
+
puts "✅ Report generated at: #{path}/activity_tracker/report.yml"
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.collect_data(path)
|
21
|
+
{
|
22
|
+
ruby_version: `ruby -v`.strip,
|
23
|
+
rails_version: get_rails_version(path),
|
24
|
+
database: detect_database(path),
|
25
|
+
models: list_and_count_files(path, "app/models"),
|
26
|
+
controllers: list_and_count_files(path, "app/controllers"),
|
27
|
+
jobs: list_and_count_files(path, "app/jobs"),
|
28
|
+
mailers: list_and_count_files(path, "app/mailers"),
|
29
|
+
services: list_and_count_files(path, "app/services"),
|
30
|
+
migrations: migration_changes(path),
|
31
|
+
schema_hash: schema_hash(path),
|
32
|
+
routes: get_routes(path),
|
33
|
+
git_log: get_git_log(path)
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.report
|
38
|
+
file = "activity_tracker/report.yml"
|
39
|
+
if File.exist?(file)
|
40
|
+
puts YAML.load_file(file).to_yaml
|
41
|
+
else
|
42
|
+
puts "❌ No report found. Please run tracking first."
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.list_and_count_files(base, dir)
|
47
|
+
path = File.join(base, dir)
|
48
|
+
files = Dir.glob("#{path}/**/*.rb").map { |f| f.gsub(base + '/', '') }
|
49
|
+
{
|
50
|
+
count: files.count,
|
51
|
+
files: files
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.get_rails_version(path)
|
56
|
+
gemfile = File.join(path, 'Gemfile.lock')
|
57
|
+
return 'Not a Rails project' unless File.exist?(gemfile)
|
58
|
+
|
59
|
+
File.read(gemfile)[/rails \((.*?)\)/, 1]
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.detect_database(path)
|
63
|
+
db_file = File.join(path, "config/database.yml")
|
64
|
+
return 'Unknown' unless File.exist?(db_file)
|
65
|
+
|
66
|
+
config = YAML.load_file(db_file, aliases: true)
|
67
|
+
config["development"]["adapter"] rescue "Unknown"
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.get_routes(path)
|
71
|
+
output = `cd #{path} && RAILS_ENV=development bundle exec rails routes 2>/dev/null`
|
72
|
+
output.empty? ? "No routes found or Rails not installed" : output
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.migration_changes(path)
|
76
|
+
files = Dir.glob("#{path}/db/migrate/*.rb")
|
77
|
+
recent = files.sort_by { |f| File.mtime(f) }.last(10)
|
78
|
+
{
|
79
|
+
count: files.count,
|
80
|
+
recent_changes: recent.map { |f| File.basename(f, ".rb").gsub(/^\d+_/, '') }
|
81
|
+
}
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.schema_hash(path)
|
85
|
+
file = File.join(path, "db/schema.rb")
|
86
|
+
return nil unless File.exist?(file)
|
87
|
+
Digest::MD5.hexdigest(File.read(file))
|
88
|
+
end
|
89
|
+
|
90
|
+
def self.get_git_log(path)
|
91
|
+
Dir.chdir(path) do
|
92
|
+
log = `git log --pretty=format:'%h - %an (%ad): %s' --date=short -n 20`
|
93
|
+
log.split("\n")
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.export(path, format = :json)
|
98
|
+
file = "#{path}/activity_tracker/report.yml"
|
99
|
+
return puts "❌ Report not found." unless File.exist?(file)
|
100
|
+
|
101
|
+
data = YAML.load_file(file)
|
102
|
+
|
103
|
+
case format
|
104
|
+
when :json
|
105
|
+
File.write("#{path}/activity_tracker/report.json", JSON.pretty_generate(data))
|
106
|
+
puts "✅ Exported to report.json"
|
107
|
+
when :csv
|
108
|
+
CSV.open("#{path}/activity_tracker/report.csv", "w") do |csv|
|
109
|
+
csv << ["Key", "Value"]
|
110
|
+
data.each do |key, value|
|
111
|
+
if value.is_a?(Hash)
|
112
|
+
csv << [key.to_s, ""]
|
113
|
+
value.each { |k, v| csv << [" #{k}", v] }
|
114
|
+
elsif value.is_a?(Array)
|
115
|
+
csv << [key.to_s, "#{value.count} items"]
|
116
|
+
value.each { |item| csv << ["", item] }
|
117
|
+
else
|
118
|
+
csv << [key.to_s, value]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
puts "✅ Exported to report.csv"
|
123
|
+
else
|
124
|
+
puts "❌ Unsupported format: #{format}"
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'listen'
|
2
|
+
require 'fileutils'
|
3
|
+
|
4
|
+
module GemActivityTracker
|
5
|
+
class Watcher
|
6
|
+
def self.start(path)
|
7
|
+
puts "👀 Watching for changes in: #{path}"
|
8
|
+
|
9
|
+
listener = Listen.to(path, ignore: [%r{activity_tracker/}, %r{tmp/}, %r{log/}, /\.log$/]) do |modified, added, removed|
|
10
|
+
changes = { modified: modified, added: added, removed: removed }
|
11
|
+
log_file = File.join(path, "activity_tracker", "log.txt")
|
12
|
+
FileUtils.mkdir_p(File.dirname(log_file))
|
13
|
+
|
14
|
+
any_change = false
|
15
|
+
|
16
|
+
changes.each do |type, files|
|
17
|
+
next if files.empty?
|
18
|
+
|
19
|
+
files.each do |file|
|
20
|
+
timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
21
|
+
relative_path = file.sub("#{path}/", '')
|
22
|
+
log_line = "[#{timestamp}] #{type.to_s.capitalize}: #{relative_path}"
|
23
|
+
puts log_line
|
24
|
+
File.open(log_file, "a") { |f| f.puts log_line }
|
25
|
+
any_change = true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if any_change
|
30
|
+
puts "🔄 Updating activity report..."
|
31
|
+
GemActivityTracker::Tracker.track(path)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
listener.start
|
36
|
+
puts "✅ Watcher started. Press Ctrl+C to stop."
|
37
|
+
sleep
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_activity_tracker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Atul Yadav
|
@@ -33,12 +33,17 @@ executables:
|
|
33
33
|
extensions: []
|
34
34
|
extra_rdoc_files: []
|
35
35
|
files:
|
36
|
+
- ".gem_activity_tracker.gemspec.swp"
|
36
37
|
- CHANGELOG.md
|
37
38
|
- README.md
|
38
39
|
- Rakefile
|
39
40
|
- exe/gem_activity_tracker
|
41
|
+
- gem_activity_tracker-0.1.0.gem
|
40
42
|
- lib/gem_activity_tracker.rb
|
43
|
+
- lib/gem_activity_tracker/railtie.rb
|
44
|
+
- lib/gem_activity_tracker/tracker.rb
|
41
45
|
- lib/gem_activity_tracker/version.rb
|
46
|
+
- lib/gem_activity_tracker/watcher.rb
|
42
47
|
- sig/gem_activity_tracker.rbs
|
43
48
|
homepage: https://example.com/gem_activity_tracker
|
44
49
|
licenses: []
|