dotfiled 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/main.yml +13 -4
- data/.github/workflows/rubocop.yml +23 -0
- data/.project.vim +33 -0
- data/.rspec +0 -2
- data/.rubocop.yml +18 -1
- data/.test_runner.yml +10 -0
- data/Gemfile +5 -2
- data/README.md +5 -2
- data/Rakefile +5 -1
- data/dotfiled.gemspec +3 -1
- data/exe/dotfiled +13 -0
- data/lib/dotfiled.rb +4 -2
- data/lib/dotfiled/alternative_file/file.rb +65 -0
- data/lib/dotfiled/alternative_file/finder.rb +91 -0
- data/lib/dotfiled/version.rb +1 -1
- metadata +10 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c436c1ed47bc95778085dd027239dbec73d18616333aea51579359c04c8ccca
|
4
|
+
data.tar.gz: e37d9c7391565cc46479fd6d32b274fcb11ef73e92e3e6cfb2bbc841880ce1b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8870d955bb26bbf289fdb97e020a26426ec44f85053491e3afc21ccd84430713a87b60132145b423e28d12c9abaf35106ca7c1c457e78d9f0820a50dcae12af5
|
7
|
+
data.tar.gz: fe45c061706de45e349a42b4b24940170f42c5a1c0d067b921862886d21ac79b05d4fbaf557d53da6d0174c0e0908aee368481dcf21c05198ef46be5c6e6c729
|
data/.github/workflows/main.yml
CHANGED
@@ -1,6 +1,11 @@
|
|
1
|
-
name: Ruby
|
1
|
+
name: Ruby RSpec
|
2
2
|
|
3
|
-
on:
|
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
|
19
|
+
- name: Run the rspec
|
15
20
|
run: |
|
16
21
|
gem install bundler -v 2.2.10
|
17
22
|
bundle install
|
18
|
-
bundle exec
|
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
data/.rubocop.yml
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
AllCops:
|
2
|
-
TargetRubyVersion: 2.
|
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
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
|
-
|
3
|
+
Helpers for dotfiles
|
4
4
|
|
5
|
-
|
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
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.
|
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
|
data/lib/dotfiled/version.rb
CHANGED
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.
|
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.
|
58
|
+
version: 2.7.0
|
52
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
60
|
requirements:
|
54
61
|
- - ">="
|