dotfiled 0.1.0 → 0.2.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: 141feb61fb6f5993f300812dbdec021e5ef9e6b4c7354adfef701ff9a1d20c0b
4
- data.tar.gz: d933f13b123fbed0f2ee82f80a84b8d23aa735fdbd6ba7472afdada9976123ac
3
+ metadata.gz: 6c436c1ed47bc95778085dd027239dbec73d18616333aea51579359c04c8ccca
4
+ data.tar.gz: e37d9c7391565cc46479fd6d32b274fcb11ef73e92e3e6cfb2bbc841880ce1b5
5
5
  SHA512:
6
- metadata.gz: 49ac4ef0f3708fe23b103447a92ba405f11156bd224769beed08b0be20209ac6f38d90ec8f97e77e0d98e40ab9b5bc338d8af4b67eab1fc21dd20ce9821039c3
7
- data.tar.gz: '083dcc860b3b93e0bf64e8c61e3fc32d83228c9f7e55cdee3a0adfdc3266c6e5a7dda2f63fe02e56e7fbf8134becd31c7d313f50992fe9155d7f70c2a19c9fd4'
6
+ metadata.gz: 8870d955bb26bbf289fdb97e020a26426ec44f85053491e3afc21ccd84430713a87b60132145b423e28d12c9abaf35106ca7c1c457e78d9f0820a50dcae12af5
7
+ data.tar.gz: fe45c061706de45e349a42b4b24940170f42c5a1c0d067b921862886d21ac79b05d4fbaf557d53da6d0174c0e0908aee368481dcf21c05198ef46be5c6e6c729
@@ -1,6 +1,11 @@
1
- name: Ruby
1
+ name: Ruby RSpec
2
2
 
3
- on: [push,pull_request]
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ - master
8
+ pull_request:
4
9
 
5
10
  jobs:
6
11
  build:
@@ -11,8 +16,12 @@ jobs:
11
16
  uses: ruby/setup-ruby@v1
12
17
  with:
13
18
  ruby-version: 3.0.0
14
- - name: Run the default task
19
+ - name: Run the rspec
15
20
  run: |
16
21
  gem install bundler -v 2.2.10
17
22
  bundle install
18
- bundle exec rake
23
+ bundle exec rspec
24
+ - name: Coveralls
25
+ uses: coverallsapp/github-action@master
26
+ with:
27
+ github-token: ${{ secrets.GITHUB_TOKEN }}
@@ -0,0 +1,23 @@
1
+ name: Rubocop
2
+ on:
3
+ push:
4
+ branches:
5
+ - main
6
+ - master
7
+ pull_request:
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up Ruby 3.0
15
+ uses: actions/setup-ruby@v1
16
+ with:
17
+ ruby-version: 3.0
18
+ - name: Runs rubocop
19
+ run: |
20
+ sudo apt-get -yqq install libpq-dev
21
+ gem install bundler
22
+ bundle install --jobs 4 --retry 3
23
+ bundle exec rubocop
data/.project.vim ADDED
@@ -0,0 +1,33 @@
1
+ autocmd FileType ruby nnoremap <buffer> <leader>T <esc>:call RunTestFile()<cr>
2
+ autocmd FileType ruby nnoremap <buffer> <leader>t <esc>:call RunTestFileFilteredByLine()<cr>
3
+ autocmd FileType ruby nnoremap <buffer> <leader>at <esc>:call RunAllTests()<cr>
4
+ function! RubocopFixCs(target)
5
+ let options=''
6
+ let cmd = 'bundle exec rubocop'
7
+
8
+ if filereadable('./bin/bundle')
9
+ let cmd = './bin/bundle exec rubocop'
10
+ endif
11
+
12
+ if filereadable('.rubocop.yml')
13
+ let options = ' --config=.rubocop.yml '
14
+ endif
15
+
16
+ let full_command = cmd . " -A " . options . a:target
17
+ call ClearEchoAndExecute(full_command)
18
+ endfunction
19
+
20
+ function! RunTestFileFilteredByLine()
21
+ let command = "bundle exec run_test " . expand('%') . " --line=" . line(".")
22
+ call ClearEchoAndExecute(command)
23
+ endfunction
24
+
25
+ function! RunTestFile()
26
+ let command = "bundle exec run_test " . expand('%')
27
+ call ClearEchoAndExecute(command)
28
+ endfunction
29
+
30
+ function! RunAllTests()
31
+ let command = "bundle exec run_test " . expand('%') . " --all"
32
+ call ClearEchoAndExecute(command)
33
+ endfunction
data/.rspec CHANGED
@@ -1,3 +1 @@
1
- --format documentation
2
1
  --color
3
- --require spec_helper
data/.rubocop.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.4
2
+ TargetRubyVersion: 2.7
3
+ NewCops: enable
3
4
 
4
5
  Style/StringLiterals:
5
6
  Enabled: true
@@ -11,3 +12,19 @@ Style/StringLiteralsInInterpolation:
11
12
 
12
13
  Layout/LineLength:
13
14
  Max: 120
15
+
16
+ Metrics/BlockLength:
17
+ Exclude:
18
+ - "spec/**/*_spec.rb"
19
+ Style/IfUnlessModifier:
20
+ Enabled: false
21
+
22
+ Style/ClassAndModuleChildren:
23
+ Enabled: false
24
+
25
+ Style/Documentation:
26
+ Enabled: false
27
+
28
+ Style/GuardClause:
29
+ Enabled: false
30
+
data/.test_runner.yml ADDED
@@ -0,0 +1,10 @@
1
+ # test_runner.yml
2
+ adapters:
3
+ rspec_with_spring:
4
+ adapter: custom
5
+ file_pattern: ".*_spec.rb"
6
+ command: "time bundle exec rspec"
7
+ commands:
8
+ all: "{command}"
9
+ file: "{command} {file}"
10
+ line: "{command} {file}:{line}"
data/Gemfile CHANGED
@@ -5,8 +5,11 @@ source "https://rubygems.org"
5
5
  # Specify your gem's dependencies in dotfiled.gemspec
6
6
  gemspec
7
7
 
8
+ gem "koine-test_runner"
8
9
  gem "rake", "~> 13.0"
9
-
10
10
  gem "rspec", "~> 3.0"
11
-
12
11
  gem "rubocop", "~> 1.7"
12
+ gem "rubocop-rake"
13
+ gem "rubocop-rspec"
14
+ gem "simplecov", require: false
15
+ gem "simplecov-lcov", require: false
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
1
  # Dotfiled
2
2
 
3
- 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/dotfiled`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Helpers for dotfiles
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ [![Build status](https://github.com/mjacobus/dotfiled/actions/workflows/main.yml/badge.svg)](https://github.com/mjacobus/dotfiled/actions/workflows/main.yml)
6
+ [![Rubocop](https://github.com/mjacobus/dotfiled/actions/workflows/rubocop.yml/badge.svg)](https://github.com/mjacobus/dotfiled/actions/workflows/rubocop.yml)
7
+ [![Maintainability](https://api.codeclimate.com/v1/badges/d8abe3894a889eb62a5c/maintainability)](https://codeclimate.com/github/mjacobus/dotfiled/maintainability)
8
+ [![Coverage Status](https://coveralls.io/repos/github/mjacobus/dotfiled/badge.svg)](https://coveralls.io/github/mjacobus/dotfiled)
6
9
 
7
10
  ## Installation
8
11
 
data/Rakefile CHANGED
@@ -9,4 +9,8 @@ require "rubocop/rake_task"
9
9
 
10
10
  RuboCop::RakeTask.new
11
11
 
12
- task default: %i[spec rubocop]
12
+ task :coverage do
13
+ ENV["COVERAGE"] = "true"
14
+ end
15
+
16
+ task default: %i[coverage spec rubocop]
data/dotfiled.gemspec CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ lib = File.expand_path("lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require_relative "lib/dotfiled/version"
4
6
 
5
7
  Gem::Specification.new do |spec|
@@ -12,7 +14,7 @@ Gem::Specification.new do |spec|
12
14
  spec.description = "Helpers for your dotfiles"
13
15
  spec.homepage = "https://github.com/mjacobus/dotfiled"
14
16
  spec.license = "MIT"
15
- spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
17
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
16
18
 
17
19
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
20
 
data/exe/dotfiled ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path("../lib", __dir__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+
7
+ begin
8
+ require "dotfiled"
9
+ rescue LoadError
10
+ puts "Could not load dotfiles"
11
+ end
12
+
13
+ puts Dotfiled::AlternativeFile::Finder.new.execute(ARGV.dup)
data/lib/dotfiled.rb CHANGED
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "pathname"
4
+ require "fileutils"
3
5
  require_relative "dotfiled/version"
6
+ require_relative "dotfiled/alternative_file/file"
7
+ require_relative "dotfiled/alternative_file/finder"
4
8
 
5
9
  module Dotfiled
6
- class Error < StandardError; end
7
- # Your code goes here...
8
10
  end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dotfiled
4
+ module AlternativeFile
5
+ class File
6
+ def initialize(path = "")
7
+ @path = Pathname.new(path.to_s)
8
+ end
9
+
10
+ def to_s
11
+ @path.to_s.gsub("//", "/")
12
+ end
13
+
14
+ def start_with?(prefix)
15
+ to_s.start_with?(prefix)
16
+ end
17
+
18
+ def without_prefix(prefix)
19
+ sub(/^#{prefix}/, "")
20
+ end
21
+
22
+ def match?(*args)
23
+ to_s.match?(*args)
24
+ end
25
+
26
+ def split(char = "/")
27
+ to_s.split(char)
28
+ end
29
+
30
+ def sub(find, replace)
31
+ new(to_s.sub(find, replace))
32
+ end
33
+
34
+ def gsub(find, replace)
35
+ new(to_s.gsub(find, replace))
36
+ end
37
+
38
+ def join(other_part)
39
+ new(@path.join(other_part.to_s))
40
+ end
41
+
42
+ def prefix_with(prefix)
43
+ new(prefix).join(self)
44
+ end
45
+
46
+ def exist?
47
+ ::File.exist?(to_s)
48
+ end
49
+
50
+ private
51
+
52
+ def new(path)
53
+ self.class.new(path)
54
+ end
55
+
56
+ class << self
57
+ def join(parts)
58
+ file = File.new("")
59
+ parts.flatten.each { |part| file = file.join(part) }
60
+ file
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ # rubocop:disable Metrics/AbcSize
4
+ # rubocop:disable Metrics/MethodLength
5
+ module Dotfiled
6
+ module AlternativeFile
7
+ class Finder
8
+ def execute(argv)
9
+ file = File.new(argv.first)
10
+
11
+ if file.match?(/.*_(test|spec).rb$/)
12
+ return find_alternative_for_ruby_test_file(file)
13
+ end
14
+
15
+ if file.match?(/.*\.rb$/)
16
+ find_ruby_test_file_for(file)
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ def find_ruby_test_file_for(file, prefix: File.new)
23
+ if file.match?(/^packages/)
24
+ return find_packaged_test_file_for(file)
25
+ end
26
+
27
+ if file.start_with?("public/") || file.start_with?("private/")
28
+ file = file.without_prefix("public/").without_prefix("private/")
29
+ end
30
+
31
+ minitest_folder = prefix.join("test")
32
+ minitest = minitest_folder.join(file).sub(/(lib|app)/, "").sub(".rb", "_test.rb")
33
+
34
+ rspec_folder = prefix.join("spec")
35
+ rspec = rspec_folder.join(file).sub(/(lib|app)/, "").sub(".rb", "_spec.rb")
36
+
37
+ if minitest_folder.exist? && rspec_folder.exist?
38
+ return best_candidate([rspec, minitest])
39
+ end
40
+
41
+ if minitest_folder.exist?
42
+ return minitest
43
+ end
44
+
45
+ rspec
46
+ end
47
+
48
+ def find_packaged_test_file_for(file)
49
+ parts = file.split
50
+ rejected_parts = %w[private public]
51
+
52
+ package = File.join([parts[0..1]])
53
+ file = [parts[2..]]
54
+ .flatten
55
+ .reject { |p| rejected_parts.include?(p) }
56
+ .join("/")
57
+
58
+ find_ruby_test_file_for(file, prefix: package)
59
+ end
60
+
61
+ def find_alternative_for_ruby_test_file(file, prefix: File.new)
62
+ if file.match?(/^packages/)
63
+ return find_packaged_file_for_test(file)
64
+ end
65
+
66
+ file = file
67
+ .sub(/_(test|spec).rb$/, ".rb")
68
+ .sub(%r{^(test|tests|spec|specs)/}, "")
69
+
70
+ possible_folders = ["lib", "app/models", "app", "private", "public"]
71
+ candidates = possible_folders.map { |folder| prefix.join(folder).join(file) }
72
+ best_candidate(candidates)
73
+ end
74
+
75
+ def find_packaged_file_for_test(file)
76
+ parts = file.split
77
+ package = File.join([parts[0..1]])
78
+ file = File.join([parts[2..]])
79
+ prefix = File.new(package)
80
+
81
+ find_alternative_for_ruby_test_file(file, prefix: prefix)
82
+ end
83
+
84
+ def best_candidate(candidates)
85
+ candidates.find(&:exist?) || candidates.first
86
+ end
87
+ end
88
+ end
89
+ end
90
+ # rubocop:enable Metrics/AbcSize
91
+ # rubocop:enable Metrics/MethodLength
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dotfiled
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotfiled
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Jacobus
@@ -13,14 +13,18 @@ dependencies: []
13
13
  description: Helpers for your dotfiles
14
14
  email:
15
15
  - marcelo.jacobus@gmail.com
16
- executables: []
16
+ executables:
17
+ - dotfiled
17
18
  extensions: []
18
19
  extra_rdoc_files: []
19
20
  files:
20
21
  - ".github/workflows/main.yml"
22
+ - ".github/workflows/rubocop.yml"
21
23
  - ".gitignore"
24
+ - ".project.vim"
22
25
  - ".rspec"
23
26
  - ".rubocop.yml"
27
+ - ".test_runner.yml"
24
28
  - CHANGELOG.md
25
29
  - CODE_OF_CONDUCT.md
26
30
  - Gemfile
@@ -30,7 +34,10 @@ files:
30
34
  - bin/console
31
35
  - bin/setup
32
36
  - dotfiled.gemspec
37
+ - exe/dotfiled
33
38
  - lib/dotfiled.rb
39
+ - lib/dotfiled/alternative_file/file.rb
40
+ - lib/dotfiled/alternative_file/finder.rb
34
41
  - lib/dotfiled/version.rb
35
42
  homepage: https://github.com/mjacobus/dotfiled
36
43
  licenses:
@@ -48,7 +55,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
48
55
  requirements:
49
56
  - - ">="
50
57
  - !ruby/object:Gem::Version
51
- version: 2.4.0
58
+ version: 2.7.0
52
59
  required_rubygems_version: !ruby/object:Gem::Requirement
53
60
  requirements:
54
61
  - - ">="