gem_activity_tracker 0.1.0 β 1.0.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 +4 -4
- data/README.md +160 -16
- data/exe/gem_activity_tracker +4 -15
- data/gem_activity_tracker.gemspec +22 -0
- data/lib/gem_activity_tracker/railtie.rb +43 -0
- data/lib/gem_activity_tracker/tracker.rb +207 -0
- data/lib/gem_activity_tracker/version.rb +1 -3
- data/lib/gem_activity_tracker/watcher.rb +34 -0
- data/lib/gem_activity_tracker.rb +1 -2
- metadata +13 -15
- data/CHANGELOG.md +0 -5
- data/Rakefile +0 -4
- data/sig/gem_activity_tracker.rbs +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20ff8068ac6c6d5f25370bc05493b268788fd353deb03b44c5bc7fcc5055a2a3
|
4
|
+
data.tar.gz: 21c65e1c1b3645d8a807272459d55328ba608371446d7836434ab2c56106b9e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78196e0eb4f23179194535eafcb0acda1613c1c8c96e46b43c38982b52e5673627ac0e604b3bdcec5534f9715414bf13068a05174a1bc9d4d20e5af31e9e40b7
|
7
|
+
data.tar.gz: 2ca4a582fe411cd1cb0d850b562835f7f190832d3d0dd812b986be9842e9ee685633e021d48d6f4db86f380afbce5d775a29c423ffe37439347a69e355329582
|
data/README.md
CHANGED
@@ -1,35 +1,179 @@
|
|
1
|
-
#
|
1
|
+
# π Gem Activity Tracker
|
2
2
|
|
3
|
-
|
3
|
+
**`gem_activity_tracker`** is a Ruby gem that tracks the internal structure, changes, and metadata of your **Ruby** or **Rails** projects. It generates a complete project activity report in **YAML**, with support for **JSON/CSV export**, **auto-tracking with file watcher**, and **Git log visualization**.
|
4
4
|
|
5
|
-
|
5
|
+
---
|
6
6
|
|
7
|
-
##
|
7
|
+
## π Features
|
8
8
|
|
9
|
-
|
9
|
+
- π Analyze project structure: models, controllers, jobs, services, mailers, routes, etc.
|
10
|
+
- π§ Advanced model analysis: attributes, associations, methods, validations, callbacks, and enums.
|
11
|
+
- ποΈ Migration tracking and schema hashing.
|
12
|
+
- π οΈ Detect database type from `database.yml`.
|
13
|
+
- π¦ Git history tracking (last 20 commits).
|
14
|
+
- π Auto-tracking using the `listen` gem on file changes.
|
15
|
+
- π Export report to **YAML**, **JSON**, or **CSV**.
|
16
|
+
- β
Works with both **Rails** and **plain Ruby** projects.
|
10
17
|
|
11
|
-
|
18
|
+
---
|
19
|
+
|
20
|
+
## π¦ Installation
|
21
|
+
|
22
|
+
Add this line to your application's Gemfile:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
gem 'gem_activity_tracker'
|
26
|
+
```
|
27
|
+
|
28
|
+
Then run:
|
29
|
+
|
30
|
+
```bash
|
31
|
+
bundle install
|
32
|
+
```
|
33
|
+
|
34
|
+
Or install it directly:
|
35
|
+
|
36
|
+
```bash
|
37
|
+
gem install gem_activity_tracker
|
38
|
+
```
|
39
|
+
|
40
|
+
---
|
41
|
+
|
42
|
+
## βοΈ Usage
|
43
|
+
|
44
|
+
### π Basic CLI Commands
|
12
45
|
|
13
46
|
```bash
|
14
|
-
|
47
|
+
gem_activity_tracker --track=PATH # Track a Ruby/Rails project and generate report
|
48
|
+
gem_activity_tracker --report # Show last generated report
|
49
|
+
gem_activity_tracker --export=json # Export report to JSON
|
50
|
+
gem_activity_tracker --export=csv # Export report to CSV
|
51
|
+
gem_activity_tracker --watch # Start file watcher to auto-track changes
|
15
52
|
```
|
16
53
|
|
17
|
-
|
54
|
+
### π οΈ Rails Auto-Tracking
|
55
|
+
|
56
|
+
In a Rails app, the gem automatically hooks into the app after initialization via a Railtie.
|
57
|
+
|
58
|
+
Set this in your `.env` or shell:
|
18
59
|
|
19
60
|
```bash
|
20
|
-
|
61
|
+
export GEM_ACTIVITY_TRACKER_ENABLED=true
|
21
62
|
```
|
22
63
|
|
23
|
-
|
64
|
+
Then start your Rails app and the gem will:
|
65
|
+
|
66
|
+
- Detect and track changes
|
67
|
+
- Update `activity_tracker/report.yml`
|
68
|
+
- Start watching the file system
|
69
|
+
|
70
|
+
---
|
71
|
+
|
72
|
+
## π Output
|
73
|
+
|
74
|
+
The gem creates an `activity_tracker/` folder at your project root:
|
75
|
+
|
76
|
+
```bash
|
77
|
+
activity_tracker/
|
78
|
+
βββ report.yml # Main YAML report
|
79
|
+
βββ report.json # (Optional) Exported JSON
|
80
|
+
βββ report.csv # (Optional) Exported CSV
|
81
|
+
βββ log.txt # File change logs (when watch mode is on)
|
82
|
+
```
|
83
|
+
|
84
|
+
---
|
85
|
+
|
86
|
+
## π Whatβs Tracked?
|
87
|
+
|
88
|
+
| Component | Details |
|
89
|
+
|------------|-------------------------------------------------------------------------|
|
90
|
+
| Models | Count, files, attributes, associations, methods, validations, enums |
|
91
|
+
| Controllers | List of files |
|
92
|
+
| Services | List of files |
|
93
|
+
| Mailers | List of files |
|
94
|
+
| Jobs | List of files |
|
95
|
+
| Migrations | Count and recent migration names |
|
96
|
+
| Routes | Full route listing via `rails routes` |
|
97
|
+
| Schema | Schema hash (`db/schema.rb`) |
|
98
|
+
| Git Log | Last 20 commits |
|
99
|
+
| Database | Type detected from `config/database.yml` |
|
100
|
+
|
101
|
+
---
|
102
|
+
|
103
|
+
## π Auto-Watcher
|
104
|
+
|
105
|
+
Auto-track changes in real-time using the `listen` gem:
|
106
|
+
|
107
|
+
```bash
|
108
|
+
gem_activity_tracker --watch
|
109
|
+
```
|
110
|
+
|
111
|
+
You'll see logs like:
|
112
|
+
|
113
|
+
```
|
114
|
+
[2025-04-10 12:00:00] Modified: app/models/user.rb
|
115
|
+
[2025-04-10 12:00:01] Added: app/services/new_service.rb
|
116
|
+
```
|
117
|
+
|
118
|
+
Each change triggers regeneration of the report.
|
119
|
+
|
120
|
+
---
|
121
|
+
|
122
|
+
## π§ͺ Example Output (YAML)
|
123
|
+
|
124
|
+
```yaml
|
125
|
+
ruby_version: ruby 3.2.2
|
126
|
+
rails_version: 6.1.4
|
127
|
+
database: postgresql
|
128
|
+
models:
|
129
|
+
count: 5
|
130
|
+
files:
|
131
|
+
- app/models/user.rb
|
132
|
+
- app/models/post.rb
|
133
|
+
detailed:
|
134
|
+
User:
|
135
|
+
table_name: users
|
136
|
+
attributes: [id, name, email]
|
137
|
+
associations:
|
138
|
+
has_many: [posts]
|
139
|
+
validations: ["PresenceValidator"]
|
140
|
+
callbacks: [before_create, after_save]
|
141
|
+
controllers:
|
142
|
+
count: 3
|
143
|
+
files: [...]
|
144
|
+
git_log:
|
145
|
+
- "1a2b3c4 - Atul Yadav (2025-04-10): Add model tracker"
|
146
|
+
- ...
|
147
|
+
```
|
148
|
+
|
149
|
+
---
|
150
|
+
|
151
|
+
## π‘ Configuration
|
152
|
+
|
153
|
+
You can toggle auto-tracking with an ENV variable:
|
154
|
+
|
155
|
+
```bash
|
156
|
+
export GEM_ACTIVITY_TRACKER_ENABLED=false # disables auto-tracking
|
157
|
+
```
|
158
|
+
|
159
|
+
---
|
160
|
+
|
161
|
+
## π§ Author
|
162
|
+
|
163
|
+
**Atul Yadav**
|
164
|
+
π§ atuIyadav9039@gmail.com
|
165
|
+
π Indore, India
|
166
|
+
π [LinkedIn](https://www.linkedin.com/in/atul-yadav-9445ab1a4)
|
167
|
+
π¦ RubyGems: [gem_activity_tracker](https://rubygems.org/gems/gem_activity_tracker)
|
24
168
|
|
25
|
-
|
169
|
+
---
|
26
170
|
|
27
|
-
##
|
171
|
+
## π License
|
28
172
|
|
29
|
-
|
173
|
+
This project is licensed under the MIT License. See `LICENSE.txt` for details.
|
30
174
|
|
31
|
-
|
175
|
+
---
|
32
176
|
|
33
|
-
## Contributing
|
177
|
+
## π¬ Contributing
|
34
178
|
|
35
|
-
|
179
|
+
Pull requests are welcome! For major changes, please open an issue first to discuss what you'd like to change.
|
data/exe/gem_activity_tracker
CHANGED
@@ -8,21 +8,10 @@ options = {}
|
|
8
8
|
OptionParser.new do |opts|
|
9
9
|
opts.banner = "Usage: gem_activity_tracker [options]"
|
10
10
|
|
11
|
-
opts.on("-tPATH", "--track=PATH", "Track a Rails/Ruby project")
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
opts.on("-r", "--report", "Show last generated report") do
|
16
|
-
options[:report] = true
|
17
|
-
end
|
18
|
-
|
19
|
-
opts.on("-eFORMAT", "--export=FORMAT", "Export as json or csv") do |format|
|
20
|
-
options[:export] = format.to_sym
|
21
|
-
end
|
22
|
-
|
23
|
-
opts.on("-w", "--watch", "Start the file watcher") do
|
24
|
-
options[:watch] = true
|
25
|
-
end
|
11
|
+
opts.on("-tPATH", "--track=PATH", "Track a Rails/Ruby project") { |v| options[:track] = v }
|
12
|
+
opts.on("-r", "--report", "Show last generated report") { options[:report] = true }
|
13
|
+
opts.on("-eFORMAT", "--export=FORMAT", "Export as json or csv") { |v| options[:export] = v.to_sym }
|
14
|
+
opts.on("-w", "--watch", "Start the file watcher") { options[:watch] = true }
|
26
15
|
end.parse!
|
27
16
|
|
28
17
|
if options[:track]
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require_relative "lib/gem_activity_tracker/version"
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = "gem_activity_tracker"
|
6
|
+
spec.version = GemActivityTracker::VERSION
|
7
|
+
spec.authors = ["Atul Yadav"]
|
8
|
+
spec.email = ["atulyadav9039@gmail.com"]
|
9
|
+
|
10
|
+
spec.summary = "Track gem and project activity in Ruby/Rails projects"
|
11
|
+
spec.description = "A CLI gem to analyze Ruby/Rails projects and track activity: models, migrations, routes, Git, schema, and more."
|
12
|
+
spec.homepage = "https://github.com/atul13055/gem_activity_tracker"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = Dir["lib/**/*.rb", "exe/*", "README.md", "LICENSE.txt", "*.gemspec"]
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = ["gem_activity_tracker"]
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
spec.required_ruby_version = ">= 3.1.0"
|
20
|
+
|
21
|
+
spec.add_dependency "listen", "~> 3.0"
|
22
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'rails/railtie'
|
2
|
+
|
3
|
+
module GemActivityTracker
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
initializer "gem_activity_tracker.auto_track" do
|
6
|
+
Rails.application.config.after_initialize do
|
7
|
+
# Delay the execution slightly to avoid blocking boot
|
8
|
+
Thread.new do
|
9
|
+
sleep(2) # Give Rails a moment to fully start
|
10
|
+
|
11
|
+
begin
|
12
|
+
path = Rails.root.to_s
|
13
|
+
report_path = File.join(path, "activity_tracker", "report.yml")
|
14
|
+
tracking_enabled = ENV.fetch('GEM_ACTIVITY_TRACKER_ENABLED', 'true') == 'true'
|
15
|
+
|
16
|
+
if tracking_enabled
|
17
|
+
Rails.logger.info "[GemActivityTracker] π Checking for project changes..."
|
18
|
+
|
19
|
+
last_data = File.exist?(report_path) ? YAML.load_file(report_path) : {}
|
20
|
+
|
21
|
+
current_data = GemActivityTracker::Tracker.collect_data(path)
|
22
|
+
|
23
|
+
if last_data != current_data
|
24
|
+
Rails.logger.info "[GemActivityTracker] π Project activity changed. Updating report..."
|
25
|
+
GemActivityTracker::Tracker.track(path)
|
26
|
+
else
|
27
|
+
Rails.logger.info "[GemActivityTracker] β
No project changes detected."
|
28
|
+
end
|
29
|
+
|
30
|
+
Rails.logger.info "[GemActivityTracker] π Starting auto-watcher for #{path}..."
|
31
|
+
GemActivityTracker::Watcher.start(path)
|
32
|
+
else
|
33
|
+
Rails.logger.info "[GemActivityTracker] βοΈ Auto-tracking disabled via ENV."
|
34
|
+
end
|
35
|
+
rescue => e
|
36
|
+
Rails.logger.error "[GemActivityTracker] β οΈ Error: #{e.message}"
|
37
|
+
Rails.logger.error e.backtrace.join("\n")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,207 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'json'
|
3
|
+
require 'fileutils'
|
4
|
+
require 'csv'
|
5
|
+
require 'digest'
|
6
|
+
require 'active_support/all'
|
7
|
+
require 'active_record'
|
8
|
+
require 'active_support/dependencies'
|
9
|
+
|
10
|
+
module GemActivityTracker
|
11
|
+
class Tracker
|
12
|
+
def self.track(path)
|
13
|
+
puts "π Tracking project at: #{path}"
|
14
|
+
|
15
|
+
if !defined?(Rails) || Rails.root.to_s != path
|
16
|
+
# Only require environment if we're not already inside a Rails app
|
17
|
+
$LOAD_PATH.unshift(path)
|
18
|
+
ENV['RAILS_ENV'] ||= 'development'
|
19
|
+
require File.join(path, 'config', 'environment')
|
20
|
+
end
|
21
|
+
|
22
|
+
data = collect_data(path)
|
23
|
+
FileUtils.mkdir_p("#{path}/activity_tracker")
|
24
|
+
File.write("#{path}/activity_tracker/report.yml", data.to_yaml)
|
25
|
+
|
26
|
+
puts "β
Report generated at: #{path}/activity_tracker/report.yml"
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.collect_data(path)
|
30
|
+
{
|
31
|
+
project_name: File.basename(path),
|
32
|
+
ruby_version: `ruby -v`.strip,
|
33
|
+
# rails_version: get_rails_version(path),
|
34
|
+
rails_version: Rails.version,
|
35
|
+
database: detect_database(path),
|
36
|
+
models: analyze_models(path),
|
37
|
+
controllers: list_and_count_files(path, "app/controllers"),
|
38
|
+
jobs: list_and_count_files(path, "app/jobs"),
|
39
|
+
mailers: list_and_count_files(path, "app/mailers"),
|
40
|
+
services: list_and_count_files(path, "app/services"),
|
41
|
+
migrations: migration_changes(path),
|
42
|
+
schema_hash: schema_hash(path),
|
43
|
+
routes: get_routes(path),
|
44
|
+
git_log: get_git_log(path)
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.report
|
49
|
+
file = "activity_tracker/report.yml"
|
50
|
+
puts File.exist?(file) ? YAML.load_file(file).to_yaml : "β No report found."
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.list_and_count_files(base, dir)
|
54
|
+
path = File.join(base, dir)
|
55
|
+
files = Dir.glob("#{path}/**/*.rb").map { |f| f.gsub(base + '/', '') }
|
56
|
+
{ count: files.count, files: files }
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.get_rails_version(path)
|
60
|
+
gemfile = File.join(path, 'Gemfile.lock')
|
61
|
+
File.exist?(gemfile) ? File.read(gemfile)[/rails \((.*?)\)/, 1] : 'Not a Rails project'
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.detect_database(path)
|
65
|
+
db_file = File.join(path, "config/database.yml")
|
66
|
+
return 'Unknown' unless File.exist?(db_file)
|
67
|
+
|
68
|
+
config = YAML.load_file(db_file, aliases: true)
|
69
|
+
config["development"]["adapter"] rescue "Unknown"
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.get_routes(path)
|
73
|
+
output = `cd #{path} && RAILS_ENV=development bundle exec rails routes 2>/dev/null`
|
74
|
+
output.empty? ? "No routes found or Rails not installed" : output
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.migration_changes(path)
|
78
|
+
files = Dir.glob("#{path}/db/migrate/*.rb")
|
79
|
+
recent = files.sort_by { |f| File.mtime(f) }.last(10)
|
80
|
+
{
|
81
|
+
count: files.count,
|
82
|
+
recent_changes: recent.map { |f| File.basename(f, ".rb").gsub(/^\d+_/, '') }
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.schema_hash(path)
|
87
|
+
file = File.join(path, "db/schema.rb")
|
88
|
+
File.exist?(file) ? Digest::MD5.hexdigest(File.read(file)) : nil
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.get_git_log(path)
|
92
|
+
Dir.chdir(path) do
|
93
|
+
log = `git log --pretty=format:'%h - %an (%ad): %s' --date=short -n 20`
|
94
|
+
log.split("\n")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.analyze_models(path)
|
99
|
+
result = { count: 0, files: [], detailed: {} }
|
100
|
+
|
101
|
+
ActiveSupport::Dependencies.autoload_paths += Dir["#{path}/app/models/**/"]
|
102
|
+
|
103
|
+
Dir.glob("#{path}/app/models/**/*.rb").each do |file|
|
104
|
+
relative_path = file.gsub("#{path}/", '')
|
105
|
+
model_name = relative_path.sub('app/models/', '').sub('.rb', '').camelize
|
106
|
+
|
107
|
+
begin
|
108
|
+
require_dependency file
|
109
|
+
model_class = model_name.constantize
|
110
|
+
next unless model_class < ActiveRecord::Base
|
111
|
+
|
112
|
+
result[:count] += 1
|
113
|
+
result[:files] << relative_path
|
114
|
+
|
115
|
+
# Validations
|
116
|
+
validations = Hash.new { |hash, key| hash[key] = [] }
|
117
|
+
model_class.validators.each do |validator|
|
118
|
+
validator.attributes.each do |attr|
|
119
|
+
validations[attr] << validator.class.name.demodulize.underscore
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Callbacks
|
124
|
+
callbacks = {}
|
125
|
+
ActiveRecord::Callbacks::CALLBACKS.each do |cb|
|
126
|
+
if model_class.respond_to?("_#{cb}_callbacks")
|
127
|
+
methods = model_class.send("_#{cb}_callbacks").map(&:filter).uniq
|
128
|
+
callbacks[cb] = methods.map(&:to_s) if methods.any?
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
# Enums
|
133
|
+
# debugger
|
134
|
+
enums = model_class.defined_enums.transform_values { |v| v.keys }
|
135
|
+
|
136
|
+
# Associations
|
137
|
+
associations = model_class.reflect_on_all_associations.group_by(&:macro).transform_values { |a| a.map(&:name) }
|
138
|
+
|
139
|
+
# Scopes
|
140
|
+
scopes = model_class.methods(false).select do |method|
|
141
|
+
model_class.method(method).source_location&.first&.include?('/models/')
|
142
|
+
end.select { |m| model_class.respond_to?(m) && model_class.send(m).is_a?(ActiveRecord::Relation) rescue false }
|
143
|
+
|
144
|
+
# Class methods
|
145
|
+
class_methods = (model_class.methods(false) - ActiveRecord::Base.methods)
|
146
|
+
instance_methods = (model_class.instance_methods(false) - ActiveRecord::Base.instance_methods).map(&:to_s)
|
147
|
+
|
148
|
+
# # Comments
|
149
|
+
# comment = File.foreach(file).first if File.read(file).lines.first.strip.start_with?('#')
|
150
|
+
|
151
|
+
result[:detailed][model_class.name] = {
|
152
|
+
table_name: model_class.table_name,
|
153
|
+
file: relative_path,
|
154
|
+
# comment: comment&.strip,
|
155
|
+
attributes: model_class.columns.map(&:name),
|
156
|
+
associations: associations,
|
157
|
+
validations: validations,
|
158
|
+
enums: enums,
|
159
|
+
callbacks: callbacks,
|
160
|
+
scopes: scopes.map(&:to_s),
|
161
|
+
class_methods: class_methods.map(&:to_s),
|
162
|
+
instance_methods: instance_methods,
|
163
|
+
methods_count: model_class.instance_methods(false).count
|
164
|
+
}
|
165
|
+
|
166
|
+
rescue => e
|
167
|
+
result[:detailed][model_name] = { error: "Failed to load: #{e.message}" }
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
result
|
172
|
+
end
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
def self.export(path, format = :json)
|
177
|
+
file = "#{path}/activity_tracker/report.yml"
|
178
|
+
return puts "β Report not found." unless File.exist?(file)
|
179
|
+
|
180
|
+
data = YAML.load_file(file)
|
181
|
+
|
182
|
+
case format
|
183
|
+
when :json
|
184
|
+
File.write("#{path}/activity_tracker/report.json", JSON.pretty_generate(data))
|
185
|
+
puts "β
Exported to report.json"
|
186
|
+
when :csv
|
187
|
+
CSV.open("#{path}/activity_tracker/report.csv", "w") do |csv|
|
188
|
+
csv << ["Key", "Value"]
|
189
|
+
data.each do |key, value|
|
190
|
+
if value.is_a?(Hash)
|
191
|
+
csv << [key.to_s, ""]
|
192
|
+
value.each { |k, v| csv << [" #{k}", v.to_json] }
|
193
|
+
elsif value.is_a?(Array)
|
194
|
+
csv << [key.to_s, "#{value.count} items"]
|
195
|
+
value.each { |item| csv << ["", item] }
|
196
|
+
else
|
197
|
+
csv << [key.to_s, value]
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
puts "β
Exported to report.csv"
|
202
|
+
else
|
203
|
+
puts "β Unsupported format: #{format}"
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
@@ -0,0 +1,34 @@
|
|
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
|
+
changes.each do |type, files|
|
16
|
+
files.each do |file|
|
17
|
+
timestamp = Time.now.strftime("%Y-%m-%d %H:%M:%S")
|
18
|
+
relative_path = file.sub("#{path}/", '')
|
19
|
+
log_line = "[#{timestamp}] #{type.to_s.capitalize}: #{relative_path}"
|
20
|
+
puts log_line
|
21
|
+
File.open(log_file, "a") { |f| f.puts log_line }
|
22
|
+
any_change = true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
GemActivityTracker::Tracker.track(path) if any_change
|
27
|
+
end
|
28
|
+
|
29
|
+
listener.start
|
30
|
+
puts "β
Watcher started. Press Ctrl+C to stop."
|
31
|
+
sleep
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/gem_activity_tracker.rb
CHANGED
@@ -2,10 +2,9 @@
|
|
2
2
|
|
3
3
|
require_relative "gem_activity_tracker/version"
|
4
4
|
require_relative "gem_activity_tracker/tracker"
|
5
|
-
require_relative "gem_activity_tracker/railtie" if defined?(Rails)
|
6
5
|
require_relative "gem_activity_tracker/watcher"
|
6
|
+
require_relative "gem_activity_tracker/railtie" if defined?(Rails)
|
7
7
|
|
8
8
|
module GemActivityTracker
|
9
9
|
class Error < StandardError; end
|
10
|
-
# Additional code (if needed) goes here
|
11
10
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_activity_tracker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Atul Yadav
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-04-
|
11
|
+
date: 2025-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: listen
|
@@ -24,8 +24,8 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
|
-
description:
|
28
|
-
|
27
|
+
description: 'A CLI gem to analyze Ruby/Rails projects and track activity: models,
|
28
|
+
migrations, routes, Git, schema, and more.'
|
29
29
|
email:
|
30
30
|
- atulyadav9039@gmail.com
|
31
31
|
executables:
|
@@ -33,20 +33,18 @@ executables:
|
|
33
33
|
extensions: []
|
34
34
|
extra_rdoc_files: []
|
35
35
|
files:
|
36
|
-
- CHANGELOG.md
|
37
36
|
- README.md
|
38
|
-
- Rakefile
|
39
37
|
- exe/gem_activity_tracker
|
38
|
+
- gem_activity_tracker.gemspec
|
40
39
|
- lib/gem_activity_tracker.rb
|
40
|
+
- lib/gem_activity_tracker/railtie.rb
|
41
|
+
- lib/gem_activity_tracker/tracker.rb
|
41
42
|
- lib/gem_activity_tracker/version.rb
|
42
|
-
-
|
43
|
-
homepage: https://
|
44
|
-
licenses:
|
45
|
-
|
46
|
-
|
47
|
-
homepage_uri: https://example.com/gem_activity_tracker
|
48
|
-
source_code_uri: https://example.com/gem_activity_tracker
|
49
|
-
changelog_uri: https://example.com/gem_activity_tracker/CHANGELOG.md
|
43
|
+
- lib/gem_activity_tracker/watcher.rb
|
44
|
+
homepage: https://github.com/atul13055/gem_activity_tracker
|
45
|
+
licenses:
|
46
|
+
- MIT
|
47
|
+
metadata: {}
|
50
48
|
post_install_message:
|
51
49
|
rdoc_options: []
|
52
50
|
require_paths:
|
@@ -65,5 +63,5 @@ requirements: []
|
|
65
63
|
rubygems_version: 3.4.10
|
66
64
|
signing_key:
|
67
65
|
specification_version: 4
|
68
|
-
summary: Track gem
|
66
|
+
summary: Track gem and project activity in Ruby/Rails projects
|
69
67
|
test_files: []
|
data/CHANGELOG.md
DELETED
data/Rakefile
DELETED