pier_console_detective 0.3.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 +7 -0
- data/.github/workflows/ci.yml +26 -0
- data/.github/workflows/publish.yml +66 -0
- data/.gitignore +13 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +46 -0
- data/LICENSE +21 -0
- data/README.md +67 -0
- data/Rakefile +6 -0
- data/bin/console +12 -0
- data/bin/get_current_version.rb +1 -0
- data/bin/notify_slack_github.sh +93 -0
- data/bin/publish_gem.rb +28 -0
- data/bin/rb_lint.sh +8 -0
- data/bin/setup +8 -0
- data/lib/pier_console_detective/irb.rb +13 -0
- data/lib/pier_console_detective/mod_attr_accessor.rb +22 -0
- data/lib/pier_console_detective/utils.rb +45 -0
- data/lib/pier_console_detective/version.rb +3 -0
- data/lib/pier_console_detective.rb +26 -0
- data/pier_console_detective.gemspec +29 -0
- metadata +68 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6e44024a185ce2ab5d4f3472f9abee0931562590091468bdade607ad16d1af6b
|
4
|
+
data.tar.gz: 4c182a45385ff01f10e44aec782c6f9e64a829c56eed94fdc68d2d76706bb73a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e597dbe5a9dfda338c175796d5a238bf98fd007fe97138766db9c6fe3c7132b5cd0a497dec41968b9c25077695f4b6433c7cb947dc4b30242ed072d11ce0f05e
|
7
|
+
data.tar.gz: 3d65b45cf768c33e1d2f381547c1a4a2c36f7f8556df4290507139e9653dccd3b59698097b4ec6f249bb40f8234c581a931c36969f1de83c6d825eb283a2e78a
|
@@ -0,0 +1,26 @@
|
|
1
|
+
name: Console Detective
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
test:
|
7
|
+
|
8
|
+
runs-on: ubuntu-latest
|
9
|
+
|
10
|
+
strategy:
|
11
|
+
matrix:
|
12
|
+
ruby-version: ['2.7', '3.0', '3.1', '3.2', '3.2.2', head]
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@v2
|
16
|
+
- name: Set up Ruby
|
17
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
18
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
19
|
+
uses: ruby/setup-ruby@v1
|
20
|
+
# uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
21
|
+
with:
|
22
|
+
ruby-version: ${{ matrix.ruby-version }}
|
23
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
24
|
+
- run: mkdir -p log/ tmp/ coverage/
|
25
|
+
- name: Run tests
|
26
|
+
run: bundle exec rake
|
@@ -0,0 +1,66 @@
|
|
1
|
+
name: Publish gem
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ main ]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
publish:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
steps:
|
11
|
+
- name: Checkout code
|
12
|
+
uses: actions/checkout@v2.1.0
|
13
|
+
- name: Check if version changed
|
14
|
+
uses: tony84727/changed-file-filter@0.0.2
|
15
|
+
id: filter
|
16
|
+
with:
|
17
|
+
filters: |
|
18
|
+
version:
|
19
|
+
- 'lib/pier_console_detective/version.rb'
|
20
|
+
- name: Setup Ruby
|
21
|
+
if: steps.filter.outputs.version == 'true'
|
22
|
+
uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: 2.7.1
|
25
|
+
- name: Get version
|
26
|
+
if: steps.filter.outputs.version == 'true'
|
27
|
+
id: new_version
|
28
|
+
run: echo "##[set-output name=version;]$(ruby ./bin/get_current_version.rb)"
|
29
|
+
- name: Create tag
|
30
|
+
if: steps.filter.outputs.version == 'true'
|
31
|
+
uses: tvdias/github-tagger@v0.0.1
|
32
|
+
with:
|
33
|
+
repo-token: "${{ secrets.GITHUB_TOKEN }}"
|
34
|
+
tag: "${{ steps.new_version.outputs.version }}"
|
35
|
+
- name: Create Release
|
36
|
+
if: steps.filter.outputs.version == 'true'
|
37
|
+
id: create_release
|
38
|
+
uses: actions/create-release@v1
|
39
|
+
env:
|
40
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
41
|
+
with:
|
42
|
+
tag_name: ${{ steps.new_version.outputs.version }}
|
43
|
+
release_name: Release ${{ steps.new_version.outputs.version }}
|
44
|
+
tag_prefix: v
|
45
|
+
draft: false
|
46
|
+
prerelease: false
|
47
|
+
- name: Publish Gem
|
48
|
+
if: steps.filter.outputs.version == 'true'
|
49
|
+
env:
|
50
|
+
VERSION: ${{ steps.new_version.outputs.version }}
|
51
|
+
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
|
52
|
+
run: ruby ./bin/publish_gem.rb
|
53
|
+
- name: Notify deploy status to Slack
|
54
|
+
if: steps.filter.outputs.version == 'true'
|
55
|
+
env:
|
56
|
+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
|
57
|
+
STATUS: ${{ job.status }}
|
58
|
+
GH_MESSAGE: ${{ github.event.commits[0].message }}
|
59
|
+
GH_ACTOR: ${{ github.actor }}
|
60
|
+
GH_SHA: ${{ github.sha }}
|
61
|
+
GH_REPO: ${{ github.repository }}
|
62
|
+
APP_ENVIRONMENT: rubygems
|
63
|
+
SLACK_CHANNEL: CEBAD7R0F
|
64
|
+
LANGUAGE: "ruby" # "python", "nodejs"
|
65
|
+
DEPLOY_TARGET: ${{ github.event.repository.name }}
|
66
|
+
run: /bin/bash ./bin/notify_slack_github.sh
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
pier_console_detective (0.3.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
byebug (11.1.3)
|
10
|
+
diff-lcs (1.4.4)
|
11
|
+
docile (1.4.0)
|
12
|
+
rake (12.3.3)
|
13
|
+
rspec (3.10.0)
|
14
|
+
rspec-core (~> 3.10.0)
|
15
|
+
rspec-expectations (~> 3.10.0)
|
16
|
+
rspec-mocks (~> 3.10.0)
|
17
|
+
rspec-core (3.10.1)
|
18
|
+
rspec-support (~> 3.10.0)
|
19
|
+
rspec-expectations (3.10.1)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.10.0)
|
22
|
+
rspec-mocks (3.10.2)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.10.0)
|
25
|
+
rspec-support (3.10.2)
|
26
|
+
simplecov (0.21.2)
|
27
|
+
docile (~> 1.1)
|
28
|
+
simplecov-html (~> 0.11)
|
29
|
+
simplecov_json_formatter (~> 0.1)
|
30
|
+
simplecov-html (0.12.3)
|
31
|
+
simplecov-lcov (0.8.0)
|
32
|
+
simplecov_json_formatter (0.1.3)
|
33
|
+
|
34
|
+
PLATFORMS
|
35
|
+
ruby
|
36
|
+
|
37
|
+
DEPENDENCIES
|
38
|
+
byebug
|
39
|
+
pier_console_detective!
|
40
|
+
rake (~> 12.0)
|
41
|
+
rspec (~> 3.0)
|
42
|
+
simplecov
|
43
|
+
simplecov-lcov
|
44
|
+
|
45
|
+
BUNDLED WITH
|
46
|
+
2.2.22
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 ArunkumarN
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# PierConsoleDetective [](https://www.codacy.com?utm_source=github.com&utm_medium=referral&utm_content=arunn/pier_console_detective&utm_campaign=Badge_Grade)[](https://www.codacy.com?utm_source=github.com&utm_medium=referral&utm_content=arunn/pier_console_detective&utm_campaign=Badge_Coverage)[](https://lbesson.mit-license.org/)[](https://github.com/arunn/pier_console_detective/graphs/commit-activity)
|
2
|
+
|
3
|
+
A gem to track commands typed in rails console along with tagging in realtime. The tags can be used to identify users. This works with [IRB](https://github.com/ruby/ruby/tree/master/lib/irb) and rails console using IRB. The values for tag, logger, and memoization requirements are configurable.
|
4
|
+
|
5
|
+
IRB provide options for recording history. It has a few disadvantages:
|
6
|
+
|
7
|
+
1. It is not possible to get the logs in realtime.
|
8
|
+
2. There are no tagging options available.
|
9
|
+
3. There is no way to know the time when the command was fired.
|
10
|
+
4. If we're connecting to the console using ssh, the logs will be lost if the connection is disconnected since the logs are only written only when we exit the session.
|
11
|
+
|
12
|
+
`pier_console_detective` overcomes such disadvantages.
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
~~~~~ruby
|
18
|
+
gem 'pier_console_detective'
|
19
|
+
~~~~~
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
~~~~~sh
|
24
|
+
$ bundle install
|
25
|
+
~~~~~
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
~~~~~sh
|
29
|
+
$ gem install pier_console_detective
|
30
|
+
~~~~~
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
There are meaningful defaults for the config. If you are using rails, run `rails console`. Otherwise, `irb -rpier_console_detective` will load the respective consoles with `pier_console_detective` loaded. You can also modify `~/.irbrc` with `require pier_console_detective` to load the `pier_console_detective` by default.
|
34
|
+
|
35
|
+

|
36
|
+
|
37
|
+
The configs can be overridden by creating a file named `pier_console_detective.rb` with following code.
|
38
|
+
|
39
|
+
~~~ruby
|
40
|
+
require 'pier_console_detective'
|
41
|
+
|
42
|
+
PierConsoleDetective.setup do |config|
|
43
|
+
# logger is a logger
|
44
|
+
# default value is Logger.new(STDOUT)
|
45
|
+
config.logger = Rails.logger
|
46
|
+
|
47
|
+
# log_tag is a lambda outputting the tag to tag the log entry
|
48
|
+
# default value is the ENV['USER']
|
49
|
+
config.log_tag = -> { ENV['USER'] }
|
50
|
+
|
51
|
+
# tag_memoization is a boolean to mention if the tag should be memoized or not.
|
52
|
+
# default is true
|
53
|
+
config.tag_memoization = true
|
54
|
+
end
|
55
|
+
~~~
|
56
|
+
|
57
|
+
If you are using rails, place this file in `config/initializers` folder and run `rails console`. Otherwise, `irb -r ./pier_console_detective.rb` will load the respective consoles with `pier_console_detective` loaded with modified config. You can also modify `~/.irbrc` with `require pier_console_detective.rb` to load the modified config by default.
|
58
|
+
|
59
|
+
## Development
|
60
|
+
|
61
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. `bin/console` will run in IRB.
|
62
|
+
|
63
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
64
|
+
|
65
|
+
## Contributing
|
66
|
+
|
67
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/arunn/pier_console_detective.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require 'byebug'
|
5
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
6
|
+
# with your gem easier. You can also use a different console, if you like.
|
7
|
+
|
8
|
+
|
9
|
+
require "irb"
|
10
|
+
require "pier_console_detective" # Loading after loading irb since we want those to be present when loading pier_console_detective
|
11
|
+
|
12
|
+
IRB.start(__FILE__)
|
@@ -0,0 +1 @@
|
|
1
|
+
print Gem::Specification::load('pier_console_detective.gemspec').version.to_s
|
@@ -0,0 +1,93 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# ==================================================================================================
|
4
|
+
# Required preset env vars
|
5
|
+
# ==================================================================================================
|
6
|
+
# SLACK_WEBHOOK:
|
7
|
+
# The Slack webhook url
|
8
|
+
# Reference: https://slack.com/apps/A0F7XDUAZ-incoming-webhooks
|
9
|
+
# Please use github secrets to store it
|
10
|
+
# SLACK_CHANNEL:
|
11
|
+
# The slack channel to send message to
|
12
|
+
# How to get: https://stackoverflow.com/a/44883343/536807
|
13
|
+
# Please use github secrets to store it
|
14
|
+
# STATUS:
|
15
|
+
# The github action job status
|
16
|
+
# You can get this with `${{ job.status }}`
|
17
|
+
# GH_REPO:
|
18
|
+
# The github repository
|
19
|
+
# You can get this with `${{ github.repository }}`
|
20
|
+
# GH_MESSAGE:
|
21
|
+
# The commit message of the commit to show as code block in the slack message
|
22
|
+
# You can get this with `${{ github.event.commits[0].message }}`
|
23
|
+
# GH_ACTOR:
|
24
|
+
# The person to show as the responsible for the commit
|
25
|
+
# You can get this with `${{ github.actor }}`
|
26
|
+
# GH_SHA:
|
27
|
+
# The sha of the commit
|
28
|
+
# You can get this with `${{ github.sha }}``
|
29
|
+
# APP_ENVIRONMENT:
|
30
|
+
# The application environment, usually `production` or `staging`
|
31
|
+
# DEPLOY_TARGET:
|
32
|
+
# Where it was deployed to, usually a heroku app name
|
33
|
+
# LANGUAGE:
|
34
|
+
# The main programming language of the project. This is used to show the language
|
35
|
+
# icon on the slack message. We use a bitbucket CDN to get the images. Please test
|
36
|
+
# the image exists before setting it
|
37
|
+
# Known working values: `ruby`, `python`, `nodejs`
|
38
|
+
|
39
|
+
REPO_NAME=`cut -d "/" -f2 <<< "$GH_REPO"`
|
40
|
+
NOW=`date +'%s'`
|
41
|
+
FOOTER_ICON="https://d301sr5gafysq2.cloudfront.net/e0aa900cf99a/img/repo-avatars/$LANGUAGE.png"
|
42
|
+
USERNAME="Github"
|
43
|
+
TEXT="\`\`\`$GH_MESSAGE\`\`\`"
|
44
|
+
TITLE_LINK="https://github.com/$GH_REPO/commit/$GH_SHA/checks"
|
45
|
+
AUTHOR_NAME="$GH_ACTOR"
|
46
|
+
AUTHOR_ICON="http://github.com/$GH_ACTOR.png?size=32"
|
47
|
+
AUTHOR_LINK="http://github.com/$GH_ACTOR"
|
48
|
+
STATUS=`echo $STATUS | tr '[A-Z]' '[a-z]'`
|
49
|
+
|
50
|
+
if [ "$STATUS" = "success" ]
|
51
|
+
then
|
52
|
+
ICON_EMOJI=":ivete-happy:"
|
53
|
+
NOTIFICATION_COLOR="#5DB182"
|
54
|
+
elif [ "$STATUS" = "failure" ]
|
55
|
+
then
|
56
|
+
ICON_EMOJI=":ivete-sad:"
|
57
|
+
NOTIFICATION_COLOR="#EC6240"
|
58
|
+
else
|
59
|
+
ICON_EMOJI=":ivete:"
|
60
|
+
NOTIFICATION_COLOR="#CCCCCC"
|
61
|
+
fi
|
62
|
+
|
63
|
+
read -r -d '' body << EOF
|
64
|
+
{
|
65
|
+
"channel": "$SLACK_CHANNEL",
|
66
|
+
"username": "$USERNAME",
|
67
|
+
"icon_emoji": "$ICON_EMOJI",
|
68
|
+
"attachments": [
|
69
|
+
{
|
70
|
+
"color": "$NOTIFICATION_COLOR",
|
71
|
+
"title": "[$REPO_NAME] Deploy to $APP_ENVIRONMENT",
|
72
|
+
"text": "$TEXT",
|
73
|
+
"title_link": "$TITLE_LINK",
|
74
|
+
"fallback": "[$REPO_NAME] Successfully deployed to $APP_ENVIRONMENT",
|
75
|
+
"author_name": "$AUTHOR_NAME",
|
76
|
+
"author_icon": "$AUTHOR_ICON",
|
77
|
+
"author_link": "$AUTHOR_LINK",
|
78
|
+
"ts": $NOW,
|
79
|
+
"footer_icon": "$FOOTER_ICON",
|
80
|
+
"footer": "$REPO_NAME",
|
81
|
+
"fields": [
|
82
|
+
{ "title": "Status", "value": "$STATUS", "short": true },
|
83
|
+
{ "title": "Deployed to", "value": "$DEPLOY_TARGET", "short": true }
|
84
|
+
]
|
85
|
+
}
|
86
|
+
]
|
87
|
+
}
|
88
|
+
EOF
|
89
|
+
|
90
|
+
curl "$SLACK_WEBHOOK" \
|
91
|
+
-X POST \
|
92
|
+
-H "Content-type: application/json; charset=utf-8" \
|
93
|
+
-d "$body"
|
data/bin/publish_gem.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
def safe_system(*cmd)
|
7
|
+
exit 1 unless system(*cmd)
|
8
|
+
end
|
9
|
+
|
10
|
+
api_key = ENV['RUBYGEMS_API_KEY'] || 'dummy'
|
11
|
+
gemspec_files = Dir.glob('*.gemspec')
|
12
|
+
credentials_dir_path = "#{Dir.home}/.gem"
|
13
|
+
credentials_file_path = "#{credentials_dir_path}/credentials"
|
14
|
+
credentials = <<~END_OF_CREDENTIALS
|
15
|
+
---
|
16
|
+
:rubygems_api_key: #{api_key}
|
17
|
+
END_OF_CREDENTIALS
|
18
|
+
|
19
|
+
FileUtils.mkdir_p(credentials_dir_path)
|
20
|
+
File.open(credentials_file_path, 'w') { |f| f.write(credentials) }
|
21
|
+
FileUtils.chmod(0o600, credentials_file_path)
|
22
|
+
|
23
|
+
gemspec_files.each do |gemspec_file|
|
24
|
+
gemspec = Gem::Specification.load(gemspec_file)
|
25
|
+
gem_file = gemspec.full_name + '.gem'
|
26
|
+
safe_system('gem', 'build', gemspec_file)
|
27
|
+
safe_system('gem', 'push', gem_file)
|
28
|
+
end
|
data/bin/rb_lint.sh
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
echo "Checking changed files"
|
3
|
+
files=$(git diff --name-only origin/main -- | xargs ls -d 2>/dev/null | egrep "\.(rb|spec|rake|rhtml|rjs|rxml|erb)$")
|
4
|
+
echo "Changed files:"
|
5
|
+
echo "***"
|
6
|
+
echo "$files"
|
7
|
+
echo "***"
|
8
|
+
if [ -z "$files" ]; then echo "No ruby files were changed"; else echo "$files" | xargs rubocop -A ; fi
|
data/bin/setup
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
module PierConsoleDetective
|
2
|
+
module IrbLogger
|
3
|
+
def evaluate(*args, **kw)
|
4
|
+
input = args.first.chomp
|
5
|
+
PierConsoleDetective::Utils.log_command(input)
|
6
|
+
output = super(*args, **kw)
|
7
|
+
PierConsoleDetective::Utils.log_command_output(input, output)
|
8
|
+
output
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
IRB::Context.prepend(PierConsoleDetective::IrbLogger) if defined?(IRB::Context)
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# Inspired and simplified from ActiveSupport's defintion of mattr_accessor
|
2
|
+
# https://github.com/rails/rails/blob/5db5de534106a44070374810a99853f38843b1d2/activesupport/lib/active_support/core_ext/module/attribute_accessors.rb
|
3
|
+
|
4
|
+
module PierConsoleDetective
|
5
|
+
module ModAttrAccessor
|
6
|
+
def mod_attr_accessor(attr_name, default_value)
|
7
|
+
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
8
|
+
@@#{attr_name} = nil unless defined? @@#{attr_name}
|
9
|
+
|
10
|
+
def self.#{attr_name}
|
11
|
+
@@#{attr_name}
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.#{attr_name}=(obj)
|
15
|
+
@@#{attr_name} = obj
|
16
|
+
end
|
17
|
+
EOS
|
18
|
+
|
19
|
+
send("#{attr_name}=", default_value) unless default_value.nil?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'logger'
|
2
|
+
|
3
|
+
module PierConsoleDetective
|
4
|
+
module Utils
|
5
|
+
LOGGER_PROC = ->(message, data) do
|
6
|
+
PierConsoleDetective::Utils.logger.info(message, {
|
7
|
+
data: data,
|
8
|
+
tag: PierConsoleDetective::Utils.get_tag,
|
9
|
+
})
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.logger
|
13
|
+
@logger ||= PierConsoleDetective.logger
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.get_tag
|
17
|
+
return @tag if PierConsoleDetective.tag_memoization && @tag
|
18
|
+
@tag = PierConsoleDetective.log_tag.call
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.log_command(command, immediately: false)
|
22
|
+
return Thread.new {
|
23
|
+
PierConsoleDetective::Utils::LOGGER_PROC.call("Command executed", {
|
24
|
+
command: command.inspect
|
25
|
+
})
|
26
|
+
} unless immediately
|
27
|
+
PierConsoleDetective::Utils::LOGGER_PROC.call("Command executed", {
|
28
|
+
command: command.inspect
|
29
|
+
})
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.log_command_output(command, output, immediately: false)
|
33
|
+
return Thread.new {
|
34
|
+
PierConsoleDetective::Utils::LOGGER_PROC.call("Command outputed", {
|
35
|
+
command: command.inspect,
|
36
|
+
output: output.inspect,
|
37
|
+
})
|
38
|
+
} unless immediately
|
39
|
+
PierConsoleDetective::Utils::LOGGER_PROC.call("Command outputed", {
|
40
|
+
command: command.inspect,
|
41
|
+
output: output.inspect,
|
42
|
+
})
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "pier_console_detective/version"
|
2
|
+
require "pier_console_detective/mod_attr_accessor"
|
3
|
+
require "logger"
|
4
|
+
|
5
|
+
module PierConsoleDetective
|
6
|
+
extend PierConsoleDetective::ModAttrAccessor
|
7
|
+
|
8
|
+
def self.setup
|
9
|
+
yield self
|
10
|
+
end
|
11
|
+
|
12
|
+
# logger is a logger
|
13
|
+
# default value is Logger.new(STDOUT)
|
14
|
+
mod_attr_accessor :logger, Logger.new(STDOUT)
|
15
|
+
|
16
|
+
# log_tag is a lambda outputting the tag to tag the log entry
|
17
|
+
# default value is the ENV['USER']
|
18
|
+
mod_attr_accessor :log_tag, -> { ENV['USER'] }
|
19
|
+
|
20
|
+
# tag_memoization is a boolean to mention if the tag should be memoized or not.
|
21
|
+
# default is true
|
22
|
+
mod_attr_accessor :tag_memoization, true
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'pier_console_detective/utils'
|
26
|
+
require 'pier_console_detective/irb'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'lib/pier_console_detective/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "pier_console_detective"
|
5
|
+
spec.version = PierConsoleDetective::VERSION
|
6
|
+
spec.authors = ["ArunkumarN"]
|
7
|
+
spec.email = ["arunn@arunn.dev"]
|
8
|
+
spec.licenses = ["MIT"]
|
9
|
+
|
10
|
+
spec.summary = %q{Track rails console user activity in real time}
|
11
|
+
spec.description = %q{Commands typed in rails console will be tracked realtime in a log file in the given format}
|
12
|
+
spec.homepage = "https://github.com/arunn/pier_console_detective"
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
14
|
+
|
15
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/arunn/pier_console_detective"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/arunn/pier_console_detective/CHANGELOG.md"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pier_console_detective
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ArunkumarN
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-05-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Commands typed in rails console will be tracked realtime in a log file
|
14
|
+
in the given format
|
15
|
+
email:
|
16
|
+
- arunn@arunn.dev
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".github/workflows/ci.yml"
|
22
|
+
- ".github/workflows/publish.yml"
|
23
|
+
- ".gitignore"
|
24
|
+
- Gemfile
|
25
|
+
- Gemfile.lock
|
26
|
+
- LICENSE
|
27
|
+
- README.md
|
28
|
+
- Rakefile
|
29
|
+
- bin/console
|
30
|
+
- bin/get_current_version.rb
|
31
|
+
- bin/notify_slack_github.sh
|
32
|
+
- bin/publish_gem.rb
|
33
|
+
- bin/rb_lint.sh
|
34
|
+
- bin/setup
|
35
|
+
- lib/pier_console_detective.rb
|
36
|
+
- lib/pier_console_detective/irb.rb
|
37
|
+
- lib/pier_console_detective/mod_attr_accessor.rb
|
38
|
+
- lib/pier_console_detective/utils.rb
|
39
|
+
- lib/pier_console_detective/version.rb
|
40
|
+
- pier_console_detective.gemspec
|
41
|
+
homepage: https://github.com/arunn/pier_console_detective
|
42
|
+
licenses:
|
43
|
+
- MIT
|
44
|
+
metadata:
|
45
|
+
allowed_push_host: https://rubygems.org
|
46
|
+
homepage_uri: https://github.com/arunn/pier_console_detective
|
47
|
+
source_code_uri: https://github.com/arunn/pier_console_detective
|
48
|
+
changelog_uri: https://github.com/arunn/pier_console_detective/CHANGELOG.md
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: 2.3.0
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
requirements: []
|
64
|
+
rubygems_version: 3.1.2
|
65
|
+
signing_key:
|
66
|
+
specification_version: 4
|
67
|
+
summary: Track rails console user activity in real time
|
68
|
+
test_files: []
|