amyf 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a5d0fa8216e89853632df3be6edc961e2a7fdaa5efe16131ba52a4f99d29d70
4
- data.tar.gz: f387b49f17afa798643301c328bb3780c88cc403e4e7c668e9a76819394df2fc
3
+ metadata.gz: f68cfce1ffcc6f197de963ddce6764f6254c7cea5bb1d7ac2ef7f4956554375b
4
+ data.tar.gz: 0db14a09d8b4615bc9fec17e2480eef425c6e0bf6b2f7b0a7ebbf6f938f72fbd
5
5
  SHA512:
6
- metadata.gz: df0940c6975d9db15c47c91dbb1f974d279aee0b5b7942c45f451894a486059d564b47fde5ab8f5c15df9643174e0b01d462a7279bd3bdeaa3d4784c49882e9a
7
- data.tar.gz: d40e4503382555c228670f822e6a26232af0090d94b176e718d123b00c50d0565c770446ea3549d018adea8b59d6a2daed3b394ea7185db080f475b0c25d1a1e
6
+ metadata.gz: 40ef27eb44fb5ae65ef1808fd0e7e390b0326a44c9f5548219e0c010e9780c2ae185e0179271b3593d7d7869d7675ff6e02fe40d3be367af63af5c3468247086
7
+ data.tar.gz: fdb9d1adeb837019aa18ee9b1418c2bb8fd056256c8a926535095acb38b194a7df652c9ef596b5543fdb8370863e0674338c644d99a017b5826cd2d74dc19150
data/bin/amyf CHANGED
@@ -2,4 +2,4 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'amyf'
5
- puts Amy.hello_world
5
+ puts Amy.meditate
data/lib/amyf.rb CHANGED
@@ -1,8 +1,40 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'optparse'
4
+ require_relative 'battlestation'
5
+ require_relative 'roadrunner'
6
+
3
7
  # Stops to smells the roses
4
8
  module Amy
5
- def self.hello_world
6
- 'Hola amor!'
9
+ # Meditate.
10
+ # Medicate.
11
+ # Meditate.
12
+ # - IDLES
13
+ def self.meditate
14
+ options = {}
15
+ OptionParser.new do |opts|
16
+ opts.banner = cat_art
17
+ opts.on('--battleship', 'Laptop setup') { |o| options[:battleship] = o }
18
+ opts.on('-r', '--roadrunner URLS', 'Comma-separated list of GitHub repository URLs') do |github_urls|
19
+ options[:github_urls] = github_urls.split(',')
20
+ end
21
+ opts.on('-h', '--help', 'I need somebody (not just anybody)') do
22
+ puts opts
23
+ exit
24
+ end
25
+ end.parse!
26
+
27
+ Battlestation.new.setup if options[:battleship] == true
28
+ RoadRunner.new(options[:github_urls]).run if options[:github_urls]
29
+ end
30
+
31
+ def self.cat_art
32
+ <<~CAT
33
+ -----------------------
34
+ /\\_/\\
35
+ ( o.o ) dance
36
+ > ^ < break ?
37
+ -----------------------
38
+ CAT
7
39
  end
8
40
  end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
4
+ require_relative 'log'
5
+
6
+ # Responsible of handling all the command line interface logic.
7
+ # Inspired by https://github.com/bachand/battlestation
8
+ class Battlestation
9
+ # Entry point for the application logic. Here we do the command line arguments processing and
10
+ # inspect the target files.
11
+ #
12
+ # @param args [Array<String>] command line arguments
13
+ # @return [Integer] UNIX exit code
14
+ def setup(_args = ARGV)
15
+ Log.info 'installing homebrew'
16
+ system '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
17
+
18
+ Log.info 'installing Rbenv'
19
+ system 'brew install rbenv'
20
+ system 'rbenv init'
21
+
22
+ Log.ingo 'installing oh-my-zsh'
23
+ system 'sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"'
24
+
25
+ Log.success(cat_art)
26
+
27
+ $CHILD_STATUS.exitstatus
28
+ end
29
+
30
+ def self.cat_art
31
+ <<~CAT
32
+ ----------------------------------
33
+ /\\_/\\
34
+ ( o.o ) reopen your terminal
35
+ > ^ < bai !
36
+ ----------------------------------
37
+ CAT
38
+ end
39
+ end
data/lib/git_cloner.rb ADDED
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'fileutils'
4
+ require 'git'
5
+ require 'log'
6
+
7
+ # Clones git repositories locally
8
+ class GitCloner
9
+ # @param base_dir The directory to which the repositories will be copied locally
10
+ def initialize(base_dir = '.')
11
+ @base_dir = base_dir
12
+ end
13
+
14
+ # Accepts an array of GitHub repository URLs (either HTTPS or SSH links) and clones
15
+ # them locally if they have not already been cloned.
16
+ #
17
+ # @param repo_urls An array of URLs pointing to GitHub repositories
18
+ def clone_repos(repo_urls)
19
+ repo_urls.each do |url|
20
+ clone_repo(url)
21
+ end
22
+ end
23
+
24
+ def clone_repo(url)
25
+ repo_path = extract_repo_path(url)
26
+ local_path = File.join(@base_dir, repo_path)
27
+
28
+ if Dir.exist?(local_path)
29
+ Log.info "Repository already exists at #{local_path}. Skipping..."
30
+ else
31
+ Log.info "Cloning #{url} into #{local_path}..."
32
+ FileUtils.mkdir_p(local_path)
33
+ Git.clone(url, local_path)
34
+ end
35
+ end
36
+
37
+ def extract_repo_path(url)
38
+ # Extract the username and repository name from the GitHub URL
39
+ # Don't ask me what's in this monstruosity
40
+ match = url.match(%r{github\.com[:/]([^/]+)/([^/]+?)(?:\.git)?$})
41
+ raise "Invalid GitHub URL: #{url}" unless match
42
+
43
+ username = match[1]
44
+ repo_name = match[2]
45
+ "#{username}/#{repo_name}"
46
+ end
47
+ end
data/lib/log.rb ADDED
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Sends a message to the terminal
4
+ module Log
5
+ # Sends a decorated message to standard output in red
6
+ def self.success(text)
7
+ $stdout.puts "SUCCESS: \e[0;32m#{text}\e[0m"
8
+ end
9
+
10
+ # Sends a decorated message to standard error
11
+ def self.error(text)
12
+ warn "ERR: \e[0;31m#{text}\e[0m"
13
+ end
14
+
15
+ # Sends a decorated message to standard output in blue
16
+ def self.info(text)
17
+ $stdout.puts "INFO: \e[0m#{text}\e[0m"
18
+ end
19
+ end
data/lib/roadrunner.rb ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'git_cloner'
4
+
5
+ # Runs around your computer. Does things. Tries to escape the coyote.
6
+ class RoadRunner
7
+ # @param github_repos An array of URLs pointing to GitHub repositories
8
+ def initialize(github_repos)
9
+ @github_repos = github_repos
10
+ end
11
+
12
+ def run
13
+ GitCloner.new.clone_repos(@github_repos)
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec'
4
+ require_relative '../git_cloner'
5
+
6
+ RSpec.describe GitCloner do
7
+ subject(:cloner) { described_class.new }
8
+
9
+ describe '#extract_repo_path' do
10
+ it 'with a github URL with https' do
11
+ result = cloner.extract_repo_path('https://github.com/fdiaz/fdiaz.github.io.git')
12
+ expect(result).to eq 'fdiaz/fdiaz.github.io'
13
+ end
14
+
15
+ it 'with a github URL with ssh' do
16
+ result = cloner.extract_repo_path('git@github.com:fdiaz/amy.git')
17
+ expect(result).to eq 'fdiaz/amy'
18
+ end
19
+ end
20
+ end
@@ -4,31 +4,33 @@ require 'rspec'
4
4
  require_relative '../version_parser'
5
5
 
6
6
  RSpec.describe VersionParser do
7
+ subject(:parser) { described_class }
8
+
7
9
  let(:dummy_class) { Class.new { include VersionParser } }
8
10
 
9
11
  describe '#prerelease_version' do
10
12
  it 'with major, minor, patch - it returns nil for prerelease name and version' do
11
- result = subject.parse('1.2.3')
13
+ result = parser.parse('1.2.3')
12
14
  expect(result).to eq Version.new(1, 2, 3, nil, nil)
13
15
  end
14
16
 
15
17
  it 'with major, minor, patch, prerelease and no prerelease version - it assigns it a 0' do
16
- result = subject.parse('99.2.3-beta')
18
+ result = parser.parse('99.2.3-beta')
17
19
  expect(result).to eq Version.new(99, 2, 3, 'beta', 0)
18
20
  end
19
21
 
20
22
  it "with major, minor, patch, prerelease and prerelease version'" do
21
- result = subject.parse('1.02.3-alpha.238')
23
+ result = parser.parse('1.02.3-alpha.238')
22
24
  expect(result).to eq Version.new(1, 2, 3, 'alpha', 238)
23
25
  end
24
26
 
25
27
  it 'with no patch version - it assign it a 0' do
26
- result = subject.parse('1.2-rc')
28
+ result = parser.parse('1.2-rc')
27
29
  expect(result).to eq Version.new(1, 2, 0, 'rc', 0)
28
30
  end
29
31
 
30
32
  it 'with no minor version - it assigns 0 to minor and patch' do
31
- result = subject.parse('874-random')
33
+ result = parser.parse('874-random')
32
34
  expect(result).to eq Version.new(874, 0, 0, 'random', 0)
33
35
  end
34
36
  end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rspec'
4
+ require_relative '../version'
5
+
6
+ RSpec.describe Version do
7
+ describe '#to_s' do
8
+ it 'converts a simple version without prerelease info' do
9
+ version = described_class.new(1, 2, 3)
10
+ expect(version.to_s).to eq('1.2.3')
11
+ end
12
+
13
+ it 'handles a pre-release without a numeric prerelease version' do
14
+ version = described_class.new(2, 3, 4, 'rc')
15
+ expect(version.to_s).to eq('2.3.4-rc')
16
+ end
17
+
18
+ it 'handles a complex pre-release version' do
19
+ version = described_class.new(1, 0, 0, 'alpha', 42)
20
+ expect(version.to_s).to eq('1.0.0-alpha.42')
21
+ end
22
+
23
+ it 'handles a version with zero values correctly' do
24
+ version = described_class.new(0, 0, 1)
25
+ expect(version.to_s).to eq('0.0.1')
26
+ end
27
+
28
+ it 'handles a version with large numbers correctly' do
29
+ version = described_class.new(10, 99, 100)
30
+ expect(version.to_s).to eq('10.99.100')
31
+ end
32
+
33
+ it 'handles a version with no patch correctly' do
34
+ version = described_class.new(10, 99)
35
+ expect(version.to_s).to eq('10.99')
36
+ end
37
+
38
+ it 'handles a version with no minor correctly' do
39
+ version = described_class.new(30)
40
+ expect(version.to_s).to eq('30')
41
+ end
42
+ end
43
+
44
+ describe '#bump_minor' do
45
+ it 'increments the minor version by 1' do
46
+ version = described_class.new(1, 2, 3).bump_minor
47
+ expect(version.to_h).to eq described_class.new(1, 3, 0).to_h
48
+ end
49
+
50
+ it 'handles single-digit minor versions correctly' do
51
+ version = described_class.new(2, 0, 5).bump_minor
52
+ expect(version.to_h).to eq described_class.new(2, 1, 0).to_h
53
+ end
54
+
55
+ it 'handles larger minor numbers correctly' do
56
+ version = described_class.new(5, 99, 10).bump_minor
57
+ expect(version.to_h).to eq described_class.new(5, 100, 0).to_h
58
+ end
59
+
60
+ it 'works with prerelease version' do
61
+ version = described_class.new(5, 99, 10, 'beta', 2).bump_minor
62
+ expect(version.to_h).to eq described_class.new(5, 100, 0, 'beta', nil).to_h
63
+ end
64
+ end
65
+
66
+ describe '#bump_prerelease' do
67
+ it 'bumps a prerelease with no version' do
68
+ version = described_class.new(1, 2, 3, 'beta', nil).bump_prerelease
69
+ expect(version.to_h).to eq described_class.new(1, 2, 3, 'beta', 1).to_h
70
+ end
71
+ end
72
+ end
data/lib/version.rb ADDED
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ Version = Struct.new(:major, :minor, :patch, :prerelease_name, :prerelease_version) do
4
+ def to_s
5
+ return "#{major}.#{minor}.#{patch}-#{prerelease_name}.#{prerelease_version}" if prerelease_name && prerelease_version
6
+ return "#{major}.#{minor}.#{patch}-#{prerelease_name}" if prerelease_name && !prerelease_version
7
+ return "#{major}.#{minor}.#{patch}" if patch
8
+ return "#{major}.#{minor}" if minor
9
+
10
+ major.to_s
11
+ end
12
+
13
+ def bump_major
14
+ Version.new(major + 1, 0, 0, prerelease_name, nil)
15
+ end
16
+
17
+ def bump_minor
18
+ Version.new(major, minor + 1, 0, prerelease_name, nil)
19
+ end
20
+
21
+ def bump_patch
22
+ Version.new(major, minor, patch + 1, prerelease_name, nil)
23
+ end
24
+
25
+ def bump_prerelease
26
+ Version.new(major, minor, patch, prerelease_name, prerelease_version ? prerelease_version + 1 : 1)
27
+ end
28
+ end
@@ -1,11 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Version = Struct.new(:major, :minor, :patch, :prename, :preversion)
3
+ require_relative 'version'
4
4
 
5
+ # Parses a module semantic version
5
6
  module VersionParser
6
7
  def self.parse(version)
7
- _ = 0
8
-
9
8
  main_version, prerelease = version.split('-')
10
9
 
11
10
  main_parts = main_version.split('.').map(&:to_i)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amyf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - fdiaz
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-26 00:00:00.000000000 Z
10
+ date: 2025-02-08 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: Impossible to live without it
13
13
  email:
@@ -19,12 +19,20 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - bin/amyf
21
21
  - lib/amyf.rb
22
+ - lib/battlestation.rb
23
+ - lib/git_cloner.rb
24
+ - lib/log.rb
25
+ - lib/roadrunner.rb
26
+ - lib/specs/git_cloner_spec.rb
22
27
  - lib/specs/version_parser_spec.rb
28
+ - lib/specs/version_spec.rb
29
+ - lib/version.rb
23
30
  - lib/version_parser.rb
24
31
  homepage: https://twoheartedyoga.com
25
32
  licenses:
26
33
  - MIT
27
- metadata: {}
34
+ metadata:
35
+ rubygems_mfa_required: 'false'
28
36
  rdoc_options: []
29
37
  require_paths:
30
38
  - lib