memoh 1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 6cae1ec03598c86a656d5281e2d02331baf4b67f75521f8ba76a27960f2e55f4
4
+ data.tar.gz: 4c5aad00e05ba92c9aa52898fd63fb423466f4a600230c3ae0dccc1dd434f76e
5
+ SHA512:
6
+ metadata.gz: a199c2890740c4c0c700dc469f01240f94b8003f17339b332cbaa36db6b468ba1aef48270b93de233953120a116b1f5e03e024020cc9575c84c9c2fcd9e9bac0
7
+ data.tar.gz: 5a6b10c883f905df45c40ddf438638546be96fdbaf9efcef959b9c733f54b225357fc7c59074f904a200da0f34e9193bffbb6010a74b7f8f9f96d725119fc4b4
data/.DS_Store ADDED
Binary file
data/.idea/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ # Default ignored files
2
+ /shelf/
3
+ /workspace.xml
4
+ # Editor-based HTTP Client requests
5
+ /httpRequests/
6
+ # Datasource local storage ignored files
7
+ /dataSources/
8
+ /dataSources.local.xml
data/.idea/memoh.iml ADDED
@@ -0,0 +1,91 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="RUBY_MODULE" version="4">
3
+ <component name="ModuleRunConfigurationManager">
4
+ <shared />
5
+ </component>
6
+ <component name="NewModuleRootManager">
7
+ <content url="file://$MODULE_DIR$">
8
+ <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
+ <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
+ <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
+ </content>
12
+ <orderEntry type="inheritedJdk" />
13
+ <orderEntry type="sourceFolder" forTests="false" />
14
+ <orderEntry type="library" scope="PROVIDED" name="activemodel (v7.1.3.3, rbenv: 3.2.2) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="activesupport (v7.1.3.3, rbenv: 3.2.2) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, rbenv: 3.2.2) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="base64 (v0.2.0, rbenv: 3.2.2) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="bigdecimal (v3.1.8, rbenv: 3.2.2) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="bundler (v2.4.10, rbenv: 3.2.2) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="colorize (v1.1.0, rbenv: 3.2.2) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.2.3, rbenv: 3.2.2) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="connection_pool (v2.4.1, rbenv: 3.2.2) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.5.1, rbenv: 3.2.2) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="drb (v2.2.1, rbenv: 3.2.2) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="i18n (v1.14.5, rbenv: 3.2.2) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="json (v2.7.2, rbenv: 3.2.2) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="language_server-protocol (v3.17.0.3, rbenv: 3.2.2) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="minitest (v5.23.1, rbenv: 3.2.2) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="mutex_m (v0.2.0, rbenv: 3.2.2) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="parallel (v1.24.0, rbenv: 3.2.2) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="parser (v3.3.1.0, rbenv: 3.2.2) [gem]" level="application" />
32
+ <orderEntry type="library" scope="PROVIDED" name="racc (v1.8.0, rbenv: 3.2.2) [gem]" level="application" />
33
+ <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, rbenv: 3.2.2) [gem]" level="application" />
34
+ <orderEntry type="library" scope="PROVIDED" name="rake (v13.2.1, rbenv: 3.2.2) [gem]" level="application" />
35
+ <orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.9.2, rbenv: 3.2.2) [gem]" level="application" />
36
+ <orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.8, rbenv: 3.2.2) [gem]" level="application" />
37
+ <orderEntry type="library" scope="PROVIDED" name="rspec (v3.13.0, rbenv: 3.2.2) [gem]" level="application" />
38
+ <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.13.0, rbenv: 3.2.2) [gem]" level="application" />
39
+ <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.13.0, rbenv: 3.2.2) [gem]" level="application" />
40
+ <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.13.1, rbenv: 3.2.2) [gem]" level="application" />
41
+ <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.13.1, rbenv: 3.2.2) [gem]" level="application" />
42
+ <orderEntry type="library" scope="PROVIDED" name="rubocop (v1.64.0, rbenv: 3.2.2) [gem]" level="application" />
43
+ <orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.31.3, rbenv: 3.2.2) [gem]" level="application" />
44
+ <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.13.0, rbenv: 3.2.2) [gem]" level="application" />
45
+ <orderEntry type="library" scope="PROVIDED" name="strscan (v3.1.0, rbenv: 3.2.2) [gem]" level="application" />
46
+ <orderEntry type="library" scope="PROVIDED" name="thor (v1.3.1, rbenv: 3.2.2) [gem]" level="application" />
47
+ <orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.6, rbenv: 3.2.2) [gem]" level="application" />
48
+ <orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.5.0, rbenv: 3.2.2) [gem]" level="application" />
49
+ </component>
50
+ <component name="RakeTasksCache-v2">
51
+ <option name="myRootTask">
52
+ <RakeTaskImpl id="rake">
53
+ <subtasks>
54
+ <RakeTaskImpl description="Build memoh-0.1.0.gem into the pkg directory" fullCommand="build" id="build" />
55
+ <RakeTaskImpl id="build">
56
+ <subtasks>
57
+ <RakeTaskImpl description="Generate SHA512 checksum if memoh-0.1.0.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
58
+ </subtasks>
59
+ </RakeTaskImpl>
60
+ <RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
61
+ <RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
62
+ <RakeTaskImpl description="Build and install memoh-0.1.0.gem into system gems" fullCommand="install" id="install" />
63
+ <RakeTaskImpl id="install">
64
+ <subtasks>
65
+ <RakeTaskImpl description="Build and install memoh-0.1.0.gem into system gems without network access" fullCommand="install:local" id="local" />
66
+ </subtasks>
67
+ </RakeTaskImpl>
68
+ <RakeTaskImpl description="Create tag v0.1.0 and build and push memoh-0.1.0.gem to TODO: Set to your gem server 'https://example.com'" fullCommand="release[remote]" id="release[remote]" />
69
+ <RakeTaskImpl description="Run RuboCop" fullCommand="rubocop" id="rubocop" />
70
+ <RakeTaskImpl id="rubocop">
71
+ <subtasks>
72
+ <RakeTaskImpl description="Autocorrect RuboCop offenses (only when it's safe)" fullCommand="rubocop:autocorrect" id="autocorrect" />
73
+ <RakeTaskImpl description="Autocorrect RuboCop offenses (safe and unsafe)" fullCommand="rubocop:autocorrect_all" id="autocorrect_all" />
74
+ <RakeTaskImpl description="" fullCommand="rubocop:auto_correct" id="auto_correct" />
75
+ </subtasks>
76
+ </RakeTaskImpl>
77
+ <RakeTaskImpl description="Run RSpec code examples" fullCommand="spec" id="spec" />
78
+ <RakeTaskImpl description="" fullCommand="default" id="default" />
79
+ <RakeTaskImpl description="" fullCommand="release" id="release" />
80
+ <RakeTaskImpl id="release">
81
+ <subtasks>
82
+ <RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
83
+ <RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
84
+ <RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
85
+ </subtasks>
86
+ </RakeTaskImpl>
87
+ </subtasks>
88
+ </RakeTaskImpl>
89
+ </option>
90
+ </component>
91
+ </module>
data/.idea/misc.xml ADDED
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectRootManager" version="2" project-jdk-name="rbenv: 3.2.2" project-jdk-type="RUBY_SDK" />
4
+ </project>
data/.idea/modules.xml ADDED
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/memoh.iml" filepath="$PROJECT_DIR$/.idea/memoh.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
data/.idea/vcs.xml ADDED
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="VcsDirectoryMappings">
4
+ <mapping directory="" vcs="Git" />
5
+ </component>
6
+ </project>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2024-05-26
4
+
5
+ - Initial release
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in memoh.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,92 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ memoh (1.0)
5
+ activemodel (~> 7.1, >= 7.1.3.3)
6
+ activesupport (~> 7.1, >= 7.1.3.3)
7
+ colorize (~> 1.1)
8
+ thor (~> 1.3, >= 1.3.1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activemodel (7.1.3.3)
14
+ activesupport (= 7.1.3.3)
15
+ activesupport (7.1.3.3)
16
+ base64
17
+ bigdecimal
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ connection_pool (>= 2.2.5)
20
+ drb
21
+ i18n (>= 1.6, < 2)
22
+ minitest (>= 5.1)
23
+ mutex_m
24
+ tzinfo (~> 2.0)
25
+ ast (2.4.2)
26
+ base64 (0.2.0)
27
+ bigdecimal (3.1.8)
28
+ colorize (1.1.0)
29
+ concurrent-ruby (1.2.3)
30
+ connection_pool (2.4.1)
31
+ diff-lcs (1.5.1)
32
+ drb (2.2.1)
33
+ i18n (1.14.5)
34
+ concurrent-ruby (~> 1.0)
35
+ json (2.7.2)
36
+ language_server-protocol (3.17.0.3)
37
+ minitest (5.23.1)
38
+ mutex_m (0.2.0)
39
+ parallel (1.24.0)
40
+ parser (3.3.1.0)
41
+ ast (~> 2.4.1)
42
+ racc
43
+ racc (1.8.0)
44
+ rainbow (3.1.1)
45
+ rake (13.2.1)
46
+ regexp_parser (2.9.2)
47
+ rexml (3.2.8)
48
+ strscan (>= 3.0.9)
49
+ rspec (3.13.0)
50
+ rspec-core (~> 3.13.0)
51
+ rspec-expectations (~> 3.13.0)
52
+ rspec-mocks (~> 3.13.0)
53
+ rspec-core (3.13.0)
54
+ rspec-support (~> 3.13.0)
55
+ rspec-expectations (3.13.0)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.13.0)
58
+ rspec-mocks (3.13.1)
59
+ diff-lcs (>= 1.2.0, < 2.0)
60
+ rspec-support (~> 3.13.0)
61
+ rspec-support (3.13.1)
62
+ rubocop (1.64.0)
63
+ json (~> 2.3)
64
+ language_server-protocol (>= 3.17.0)
65
+ parallel (~> 1.10)
66
+ parser (>= 3.3.0.2)
67
+ rainbow (>= 2.2.2, < 4.0)
68
+ regexp_parser (>= 1.8, < 3.0)
69
+ rexml (>= 3.2.5, < 4.0)
70
+ rubocop-ast (>= 1.31.1, < 2.0)
71
+ ruby-progressbar (~> 1.7)
72
+ unicode-display_width (>= 2.4.0, < 3.0)
73
+ rubocop-ast (1.31.3)
74
+ parser (>= 3.3.1.0)
75
+ ruby-progressbar (1.13.0)
76
+ strscan (3.1.0)
77
+ thor (1.3.1)
78
+ tzinfo (2.0.6)
79
+ concurrent-ruby (~> 1.0)
80
+ unicode-display_width (2.5.0)
81
+
82
+ PLATFORMS
83
+ arm64-darwin-23
84
+
85
+ DEPENDENCIES
86
+ memoh!
87
+ rake (~> 13.0)
88
+ rspec (~> 3.0)
89
+ rubocop (~> 1.21)
90
+
91
+ BUNDLED WITH
92
+ 2.4.10
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Matias Salles
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # Memoh
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/memoh`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ 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.
26
+
27
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/memoh.
32
+
33
+ ## License
34
+
35
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/exe/memoh ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "memoh"
4
+
5
+ Memoh::CLI.start
data/lib/memoh/cli.rb ADDED
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ require "thor"
3
+ require "colorize"
4
+ require "active_support/core_ext/object/blank"
5
+
6
+ require_relative "models/ssh_memo"
7
+ require_relative "commands/crud"
8
+ require_relative "commands/connection"
9
+
10
+ module Memoh
11
+ class CLI < Thor # :nodoc:
12
+ include Thor::Actions
13
+
14
+ include Commands::CRUD
15
+ include Commands::Connection
16
+
17
+ desc "version", "Display Memoh version"
18
+ map %w[-v --version] => :version
19
+ def version
20
+ puts Memoh::VERSION
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Memoh
4
+ module Commands
5
+ module Connection
6
+ module Connect # :nodoc:
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ desc "connect", "Connect to host using SSH by memo name. Example: memoh connect my_server"
11
+ def connect(memo_name = nil)
12
+ memo = Models::SSHMemo.find_by(name: memo_name)
13
+
14
+ if memo.nil?
15
+ puts "There's no memo named \"#{memo_name}\" !".red
16
+ exit
17
+ end
18
+
19
+ puts "Connecting to #{memo_name}...".send(memo.color)
20
+ exec memo.connection_string
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Memoh
4
+ module Commands
5
+ module Connection
6
+ module Health # :nodoc:
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ desc "health", "Checks the health of each SSH memo"
11
+ def health
12
+ memos = Models::SSHMemo.all
13
+ invalid_memos = memos.reject(&:valid?)
14
+
15
+ if invalid_memos.empty?
16
+ puts "All memos are healthy!".green
17
+ else
18
+ puts "Oh oh :( It looks like the following memos have some issues:\n".yellow
19
+
20
+ invalid_memos.each do |memo|
21
+ puts "#{memo.name}: #{memo.errors.full_messages.join(", ")}".send(memo.color)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ require_relative "connection/connect"
6
+ require_relative "connection/health"
7
+
8
+ module Memoh
9
+ module Commands
10
+ module Connection # :nodoc:
11
+ extend ActiveSupport::Concern
12
+
13
+ included do
14
+ include Connect
15
+ include Health
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Memoh
4
+ module Commands
5
+ module CRUD
6
+ module Create
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ desc "create", "Create a new SSH memo"
11
+ def create
12
+ memo_attributes = {}
13
+
14
+ Models::SSHMemo.questions_map.each do |question_info|
15
+ attribute = ask question_info[:question]
16
+ memo_attributes[question_info[:attribute]] = attribute
17
+ end
18
+
19
+ memo = Models::SSHMemo.new(memo_attributes)
20
+
21
+ if memo.valid?
22
+ memo.save
23
+ puts "Memo created successfully!".green
24
+ else
25
+ puts "It looks like the memo's data is invalid:".red
26
+ puts memo.errors.full_messages.join(", ").red
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Memoh
4
+ module Commands
5
+ module CRUD
6
+ module Delete # :nodoc:
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ desc "delete", "Delete a memo by name"
11
+ def delete(memo_name = nil)
12
+ memo = Models::SSHMemo.find_by(name: memo_name)
13
+
14
+ if memo.nil?
15
+ puts "There's no memo named \"#{memo_name}\" !".red
16
+ exit
17
+ end
18
+
19
+ confirmation = ask "Are you sure you want to delete #{memo_name}? (y/n)"
20
+
21
+ if confirmation.downcase == "y"
22
+ memo.delete
23
+ puts "Memo #{memo.name} deleted successfully".green
24
+ else
25
+ puts "Memo deletion cancelled.".yellow
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Memoh
4
+ module Commands
5
+ module CRUD
6
+ module Index # :nodoc:
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ desc "list", "List all SSH memos"
11
+ def list
12
+ memos = Models::SSHMemo.all
13
+
14
+ memos.each do |memo|
15
+ puts memo.display_details
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Memoh
4
+ module Commands
5
+ module CRUD
6
+ module Show
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ desc "details", "Display all the details of a memo by name"
11
+ def details(memo_name = nil)
12
+ memo = Models::SSHMemo.find_by(name: memo_name)
13
+
14
+ if memo.nil?
15
+ puts "There's no memo named \"#{memo_name}\" !".red
16
+ exit
17
+ end
18
+
19
+ memo.attributes.each do |attribute, value|
20
+ puts "#{attribute.humanize}: #{value}".send(memo.color)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Memoh
4
+ module Commands
5
+ module CRUD
6
+ module Update # :nodoc:
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ desc "update", "Update a memo by name"
11
+ def update(memo_name = nil)
12
+ memo = Models::SSHMemo.find_by(name: memo_name)
13
+
14
+ if memo.nil?
15
+ puts "There's no memo named \"#{memo_name}\" !".red
16
+ exit
17
+ end
18
+
19
+ ask "Skip any field you don't want to update by hitting [ENTER]. Now, press any key to continue...".yellow
20
+ puts ""
21
+
22
+ memo_attributes = {}
23
+
24
+ Models::SSHMemo.questions_map.each do |question_info|
25
+ attribute = ask question_info[:question]
26
+ memo_attributes[question_info[:attribute]] = attribute unless attribute.blank?
27
+ end
28
+
29
+ memo.assign_attributes(memo_attributes)
30
+
31
+ if memo.valid?
32
+ memo.update
33
+ puts "Memo updated successfully!".green
34
+ else
35
+ puts "It looks like the memo's data is invalid:".red
36
+ puts memo.errors.full_messages.join(", ").red
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+
5
+ require_relative "crud/index"
6
+ require_relative "crud/show"
7
+ require_relative "crud/create"
8
+ require_relative "crud/update"
9
+ require_relative "crud/delete"
10
+
11
+ module Memoh
12
+ module Commands
13
+ module CRUD # :nodoc:
14
+ extend ActiveSupport::Concern
15
+
16
+ included do
17
+ include Index
18
+ include Show
19
+ include Create
20
+ include Update
21
+ include Delete
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Memoh
6
+ module DB
7
+ class AbstractAdapter # :nodoc:
8
+ def all
9
+ raise NotImplementedError
10
+ end
11
+
12
+ def find_by(attributes)
13
+ all.find do |obj|
14
+ attributes.all? { |key, value| obj.send(key) == value }
15
+ end
16
+ end
17
+
18
+ def create(obj)
19
+ raise NotImplementedError
20
+ end
21
+
22
+ def update(obj)
23
+ raise NotImplementedError
24
+ end
25
+
26
+ def delete(obj)
27
+ raise NotImplementedError
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ require_relative "abstract_adapter"
6
+
7
+ module Memoh
8
+ module DB
9
+ class JSONAdapter < AbstractAdapter # :nodoc:
10
+ DIRECTORY = File.expand_path("~/.memoh")
11
+ FILE_PATH = File.expand_path("#{DIRECTORY}/memoh_db.json")
12
+
13
+ def initialize(persisted_class)
14
+ @persisted_class = persisted_class
15
+ Dir.mkdir(DIRECTORY) unless Dir.exist?(DIRECTORY)
16
+ end
17
+
18
+ def all
19
+ @objects ||= begin
20
+ retrieved_json = File.exist?(FILE_PATH) ? JSON.parse(File.read(FILE_PATH)) : []
21
+ retrieved_json.map { |obj| @persisted_class.new.from_json(obj.to_json) }
22
+ end
23
+ end
24
+
25
+ def create(obj)
26
+ current_objs = all
27
+ current_objs << obj
28
+
29
+ File.open(FILE_PATH, "w") do |f|
30
+ f.write(current_objs.to_json)
31
+ end
32
+ end
33
+
34
+ def update(obj)
35
+ current_objs = all
36
+ index = current_objs.find_index do |memo|
37
+ memo.send(@persisted_class.id_field) == memo.send("#{@persisted_class.id_field}_was")
38
+ end
39
+ current_objs[index] = obj
40
+
41
+ File.open(FILE_PATH, "w") do |f|
42
+ f.write(current_objs.to_json)
43
+ end
44
+ end
45
+
46
+ def delete(obj)
47
+ current_objs = all
48
+ current_objs.reject! { |co| obj.send(@persisted_class.id_field) == co.send(@persisted_class.id_field) }
49
+
50
+ File.open(FILE_PATH, "w") do |f|
51
+ f.write(current_objs.to_json)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support/concern"
4
+ require_relative "../../db/json_adapter"
5
+
6
+ module Memoh
7
+ module Models
8
+ module Concerns
9
+ module Persistence # :nodoc:
10
+ extend ActiveSupport::Concern
11
+
12
+ included do
13
+ class_attribute :persistence_class, default: Memoh::DB::JSONAdapter
14
+ class_attribute :id_field, default: :name
15
+ end
16
+
17
+ module ClassMethods # :nodoc:
18
+ def all
19
+ persistence_manager.all
20
+ end
21
+
22
+ def find_by(attributes)
23
+ persistence_manager.find_by(attributes)
24
+ end
25
+
26
+ def persistence_manager
27
+ persistence_class.new(self)
28
+ end
29
+
30
+ def identifier_field(field)
31
+ self.id_field = field
32
+ end
33
+ end
34
+
35
+ def save
36
+ self.class.persistence_manager.create(self)
37
+ end
38
+
39
+ def update
40
+ self.class.persistence_manager.update(self)
41
+ end
42
+
43
+ def delete
44
+ self.class.persistence_manager.delete(self)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_model"
4
+ require "colorize"
5
+ require_relative "concerns/persistence"
6
+
7
+ module Memoh
8
+ module Models
9
+ class SSHMemo # :nodoc:
10
+ ALLOWED_COLORS = String.colors.map(&:to_s) - %w[black default]
11
+
12
+ include ActiveModel::Model
13
+ include ActiveModel::Attributes
14
+ include ActiveModel::Dirty
15
+ include ActiveModel::Serializers::JSON
16
+ include ActiveModel::Validations::Callbacks
17
+ include Concerns::Persistence
18
+
19
+ attribute :name, :string
20
+ attribute :username, :string
21
+ attribute :host, :string
22
+ attribute :identity_file, :string
23
+ attribute :color, :string, default: "white"
24
+
25
+ identifier_field :name
26
+
27
+ validates :name, :host, :username, :identity_file, :color, presence: true
28
+
29
+ validates :color, inclusion: { in: ALLOWED_COLORS }
30
+ validate :identity_file_existence
31
+
32
+ before_validation :expand_identity_file_path
33
+
34
+ class << self
35
+ # rubocop:disable Metrics/LineLength
36
+ def questions_map
37
+ [
38
+ { attribute: :host, question: "Enter the IP address or hostname:" },
39
+ { attribute: :username, question: "Enter the username:" },
40
+ { attribute: :identity_file, question: "Enter the path to the SSH key used for this host:" },
41
+ { attribute: :name, question: "Choose a name for your SSH memo (you'll use this name to connect to your host):" },
42
+ { attribute: :color, question: "Choose a color for your SSH memo:\n(#{ALLOWED_COLORS.map { |color| color.send(color) }.join("/")})" }
43
+ ]
44
+ end
45
+ # rubocop:enable Metrics/LineLength
46
+ end
47
+
48
+ def display_details
49
+ "Name: #{name}, Host: #{host}".send(color)
50
+ end
51
+
52
+ def connection_string
53
+ "ssh #{username}@#{host} -i #{identity_file}"
54
+ end
55
+
56
+ private
57
+
58
+ def expand_identity_file_path
59
+ return if identity_file.nil?
60
+
61
+ self.identity_file = File.expand_path(identity_file)
62
+ end
63
+
64
+ def identity_file_existence
65
+ return if File.exist?(identity_file)
66
+
67
+ errors.add(:identity_file, "does not exist")
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Memoh
4
+ VERSION = "1.0"
5
+ end
data/lib/memoh.rb ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "memoh/version"
4
+ require_relative "memoh/cli"
5
+ require_relative "memoh/models/ssh_memo"
6
+
7
+ module Memoh
8
+ class Error < StandardError; end
9
+ # Your code goes here...
10
+ end
data/memoh.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/memoh/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "memoh"
7
+ spec.version = Memoh::VERSION
8
+ spec.authors = ["Matias Salles"]
9
+ spec.email = ["matiassalles99@gmail.com"]
10
+
11
+ spec.summary = "Save your SSH connection details with memoh"
12
+ spec.description = "Save your SSH connection details with memoh and connect to any saved host by name"
13
+ spec.homepage = "https://github.com/matiassalles99/memoh"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "https://github.com/matiassalles99/memoh"
19
+ spec.metadata["changelog_uri"] = "https://github.com/matiassalles99/memoh/blob/main/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(__dir__) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (File.expand_path(f) == __FILE__) || f.start_with?(*%w[bin/ test/ spec/ features/ .git .circleci appveyor])
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables << "memoh"
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "activemodel", "~> 7.1", ">= 7.1.3.3"
33
+ spec.add_dependency "activesupport", "~> 7.1", ">= 7.1.3.3"
34
+ spec.add_dependency "colorize", "~> 1.1"
35
+ spec.add_dependency "thor", "~> 1.3", ">= 1.3.1"
36
+
37
+ # For more information and examples about making a new gem, check out our
38
+ # guide at: https://bundler.io/guides/creating_gem.html
39
+ end
data/sig/memoh.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Memoh
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: memoh
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Matias Salles
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-06-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activemodel
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '7.1'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 7.1.3.3
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '7.1'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 7.1.3.3
33
+ - !ruby/object:Gem::Dependency
34
+ name: activesupport
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '7.1'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 7.1.3.3
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '7.1'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 7.1.3.3
53
+ - !ruby/object:Gem::Dependency
54
+ name: colorize
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.1'
60
+ type: :runtime
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.1'
67
+ - !ruby/object:Gem::Dependency
68
+ name: thor
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '1.3'
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 1.3.1
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '1.3'
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 1.3.1
87
+ description: Save your SSH connection details with memoh and connect to any saved
88
+ host by name
89
+ email:
90
+ - matiassalles99@gmail.com
91
+ executables:
92
+ - memoh
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".DS_Store"
97
+ - ".idea/.gitignore"
98
+ - ".idea/memoh.iml"
99
+ - ".idea/misc.xml"
100
+ - ".idea/modules.xml"
101
+ - ".idea/vcs.xml"
102
+ - ".rspec"
103
+ - ".rubocop.yml"
104
+ - CHANGELOG.md
105
+ - Gemfile
106
+ - Gemfile.lock
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - exe/memoh
111
+ - lib/memoh.rb
112
+ - lib/memoh/cli.rb
113
+ - lib/memoh/commands/connection.rb
114
+ - lib/memoh/commands/connection/connect.rb
115
+ - lib/memoh/commands/connection/health.rb
116
+ - lib/memoh/commands/crud.rb
117
+ - lib/memoh/commands/crud/create.rb
118
+ - lib/memoh/commands/crud/delete.rb
119
+ - lib/memoh/commands/crud/index.rb
120
+ - lib/memoh/commands/crud/show.rb
121
+ - lib/memoh/commands/crud/update.rb
122
+ - lib/memoh/db/abstract_adapter.rb
123
+ - lib/memoh/db/json_adapter.rb
124
+ - lib/memoh/models/concerns/persistence.rb
125
+ - lib/memoh/models/ssh_memo.rb
126
+ - lib/memoh/version.rb
127
+ - memoh.gemspec
128
+ - sig/memoh.rbs
129
+ homepage: https://github.com/matiassalles99/memoh
130
+ licenses:
131
+ - MIT
132
+ metadata:
133
+ homepage_uri: https://github.com/matiassalles99/memoh
134
+ source_code_uri: https://github.com/matiassalles99/memoh
135
+ changelog_uri: https://github.com/matiassalles99/memoh/blob/main/CHANGELOG.md
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: 2.6.0
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - ">="
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubygems_version: 3.4.10
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Save your SSH connection details with memoh
155
+ test_files: []