space2underscore 0.5.3 → 0.6.1
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 +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +45 -17
- data/bin/s2u +1 -0
- data/lib/space2underscore/branch_creator.rb +20 -0
- data/lib/space2underscore/cli.rb +21 -48
- data/lib/space2underscore/converter.rb +24 -0
- data/lib/space2underscore/options_parser.rb +44 -0
- data/lib/space2underscore/output_printer.rb +16 -0
- data/lib/space2underscore/version.rb +1 -1
- data/lib/space2underscore.rb +4 -3
- metadata +16 -31
- data/.gitignore +0 -18
- data/.rspec +0 -2
- data/.rubocop.yml +0 -16
- data/.travis.yml +0 -17
- data/Gemfile +0 -7
- data/Rakefile +0 -23
- data/bin/s2u +0 -6
- data/lib/space2underscore/executor.rb +0 -21
- data/lib/space2underscore/printer.rb +0 -21
- data/lib/space2underscore/underscore.rb +0 -17
- data/space2underscore.gemspec +0 -30
- data/spec/space2underscore/printer_spec.rb +0 -19
- data/spec/space2underscore/underscore_spec.rb +0 -22
- data/spec/space2underscore/usage_spec.rb +0 -10
- data/spec/spec_helper.rb +0 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: dba1ba27849c81429c896976c2b3b0cc958742f16dc5f0588280aeca3f1a9ddb
|
|
4
|
+
data.tar.gz: 5fb0b0dba5cf58ac7b61e4f3309e700780d3f07f2b1848da33cc5d9163bc09e2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a2694fe66f5dc84dbe708eea7fcc14f56b6e5828ba92f860663a1aae5fed6e8133f617827bc72fc9b8a73340ba69dfb4b759404037a368584f5391cd9828fe67
|
|
7
|
+
data.tar.gz: 9887708fc1716e3d71cd3395b3ce7fe2b61a7b8e189d26d571e95515118fe85e067daec0d39b8504eeeb130512dbc9be463d4df4df1b7ed5eca91662e4c1a964
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# Space2underscore Change Log
|
|
2
2
|
|
|
3
|
+
## v0.6.1
|
|
4
|
+
- Bump minimum Ruby version to 2.7.
|
|
5
|
+
- Migrate from Travis CI to GitHub Actions.
|
|
6
|
+
- Modernize gem specification.
|
|
7
|
+
- Update RuboCop configuration with modern settings.
|
|
8
|
+
- Remove version constraint from Coveralls.
|
|
9
|
+
- Improve README with clearer structure and formatting.
|
|
10
|
+
|
|
11
|
+
## v0.6.0
|
|
12
|
+
- Fix command injection vulnerability in Executor.
|
|
13
|
+
- Simplify architecture and remove Singleton pattern.
|
|
14
|
+
- Replace duplicate s2u with symlink.
|
|
15
|
+
- Add project configuration file.
|
|
16
|
+
- Fix typos in documentation.
|
|
17
|
+
|
|
3
18
|
## v0.5.2
|
|
4
19
|
- Refactor methods in space2underscore.
|
|
5
20
|
- Refactor examples for space2underscore.
|
data/README.md
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
# Space2underscore
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A CLI tool that converts spaces into underscores. Useful for creating or renaming Git branches.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
[](https://badge.fury.io/rb/space2underscore)
|
|
6
|
+
[](https://github.com/sachin21/space2underscore/actions)
|
|
7
|
+
[](https://codeclimate.com/github/sachin21/space2underscore)
|
|
8
|
+
[](https://coveralls.io/github/sachin21/space2underscore?branch=master)
|
|
9
|
+
[](https://rubygems.org/gems/space2underscore)
|
|
6
10
|
|
|
7
|
-
|
|
8
|
-
space2underscore is a useful command when you want to check out a branch.
|
|
11
|
+
## Requirements
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
- Ruby >= 2.4.0
|
|
14
|
+
- Git
|
|
11
15
|
|
|
12
|
-
|
|
16
|
+
## Installation
|
|
13
17
|
|
|
14
18
|
```
|
|
15
19
|
$ gem install space2underscore
|
|
@@ -17,28 +21,52 @@ $ gem install space2underscore
|
|
|
17
21
|
|
|
18
22
|
## Usage
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
### Create a new branch
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
Use the `-c` (`--create`) option to create a new Git branch with spaces converted to underscores.
|
|
23
27
|
|
|
24
28
|
```
|
|
25
29
|
$ s2u new branch -c
|
|
26
|
-
=>
|
|
30
|
+
=> Switched to a new branch 'new_branch'
|
|
27
31
|
```
|
|
28
32
|
|
|
29
|
-
|
|
33
|
+
### Rename an existing branch
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
Use `$(s2u ...)` as a subcommand.
|
|
32
36
|
|
|
33
37
|
```
|
|
34
38
|
$ git branch -m $(s2u renamed branch)
|
|
35
39
|
```
|
|
36
40
|
|
|
37
|
-
|
|
41
|
+
### Print the converted string
|
|
42
|
+
|
|
43
|
+
Without any options, the converted string is printed to stdout. By default, the output is downcased.
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
$ s2u Hello World
|
|
47
|
+
hello_world
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Preserve original case
|
|
51
|
+
|
|
52
|
+
Use the `-r` (`--raw`) option to keep the original letter casing.
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
$ s2u Hello World -r
|
|
56
|
+
Hello_World
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Options
|
|
60
|
+
|
|
61
|
+
| Option | Short | Description |
|
|
62
|
+
|---|---|---|
|
|
63
|
+
| `--create` | `-c` | Create a new Git branch with the converted name |
|
|
64
|
+
| `--raw` | `-r` | Preserve original letter casing (skip downcase) |
|
|
65
|
+
|
|
66
|
+
## Caution
|
|
67
|
+
|
|
68
|
+
This is a command line tool. **DO NOT** include this module in other Ruby applications, as it uses the `system` command internally, which may introduce command injection vulnerabilities.
|
|
38
69
|
|
|
39
|
-
|
|
40
|
-
If you include this module to your application, there is a possibility of crackers attacking.
|
|
70
|
+
## License
|
|
41
71
|
|
|
42
|
-
|
|
43
|
-
- Help information based on [@motemen's ghq](https://github.com/motemen/ghq)
|
|
44
|
-
- Installed information based on [Tmuxinator](https://github.com/tmuxinator/tmuxinator)
|
|
72
|
+
[MIT License](MIT-LICENSE) - Copyright (c) 2014 Satoshi Ohmori
|
data/bin/s2u
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
space2underscore
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Space2underscore
|
|
4
|
+
# Creates git branches with secure command execution
|
|
5
|
+
class BranchCreator
|
|
6
|
+
class << self
|
|
7
|
+
# Create a new git branch with the given name
|
|
8
|
+
#
|
|
9
|
+
# @param name [String] Branch name to create
|
|
10
|
+
# @return [void]
|
|
11
|
+
# @raise [SystemExit] Exits with git command status code
|
|
12
|
+
def create(name)
|
|
13
|
+
# Use array form to prevent command injection
|
|
14
|
+
# Place branch name directly after -b as git requires,
|
|
15
|
+
# then -- to separate from any start-point ambiguity
|
|
16
|
+
exit system('git', 'checkout', '-b', name, '--')
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
data/lib/space2underscore/cli.rb
CHANGED
|
@@ -1,67 +1,40 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Space2underscore
|
|
4
|
+
# Main CLI orchestrator
|
|
4
5
|
class Cli
|
|
5
|
-
CREATE_FLAGS = %w[-c --create].freeze
|
|
6
|
-
RAW_FLAGS = %w[-r --raw].freeze
|
|
7
|
-
|
|
8
|
-
FLAGS = [CREATE_FLAGS, RAW_FLAGS].flatten.freeze
|
|
9
|
-
|
|
10
|
-
ERROR_MSG = 'Option is invalid format. It is only avaliable for `-c --create -d --downcase`'
|
|
11
|
-
|
|
12
|
-
OptionParseError = Class.new(ArgumentError)
|
|
13
|
-
|
|
14
6
|
def initialize(argv)
|
|
15
7
|
@argv = argv
|
|
16
|
-
@underscore_include_branch = Underscore.new(branch).convert
|
|
17
|
-
@executer = Executor.instance
|
|
18
|
-
@printer = Printer.instance
|
|
19
8
|
end
|
|
20
9
|
|
|
21
10
|
def start
|
|
22
|
-
|
|
11
|
+
options = OptionsParser.parse(@argv)
|
|
23
12
|
|
|
24
|
-
if
|
|
25
|
-
|
|
26
|
-
elsif create_flags_without_raw_flags?
|
|
27
|
-
@executer.run_with_downcase(@underscore_include_branch)
|
|
28
|
-
elsif raw_flags_without_create_flags?
|
|
29
|
-
@printer.run_with_raw(@underscore_include_branch)
|
|
30
|
-
elsif without_any_flags?
|
|
31
|
-
@printer.run_with_downcase(@underscore_include_branch)
|
|
32
|
-
else
|
|
33
|
-
raise OptionParseError, ERROR_MSG
|
|
34
|
-
end
|
|
35
|
-
end
|
|
13
|
+
# Show usage if no arguments
|
|
14
|
+
return display_usage unless options
|
|
36
15
|
|
|
37
|
-
|
|
16
|
+
# Convert input to branch name
|
|
17
|
+
branch_name = Converter.convert(options.input)
|
|
38
18
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
end
|
|
19
|
+
# Apply case transformation
|
|
20
|
+
branch_name = branch_name.downcase if options.downcase
|
|
42
21
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def with_all_flags?
|
|
56
|
-
included?(CREATE_FLAGS) && included?(RAW_FLAGS)
|
|
22
|
+
# Execute action
|
|
23
|
+
case options.action
|
|
24
|
+
when :create
|
|
25
|
+
BranchCreator.create(branch_name)
|
|
26
|
+
when :print
|
|
27
|
+
OutputPrinter.print(branch_name)
|
|
28
|
+
end
|
|
29
|
+
rescue OptionsParser::ParseError => e
|
|
30
|
+
$stderr.puts "Error: #{e.message}"
|
|
31
|
+
exit 1
|
|
57
32
|
end
|
|
58
33
|
|
|
59
|
-
|
|
60
|
-
included?(CREATE_FLAGS) && not_included?(RAW_FLAGS)
|
|
61
|
-
end
|
|
34
|
+
private
|
|
62
35
|
|
|
63
|
-
def
|
|
64
|
-
|
|
36
|
+
def display_usage
|
|
37
|
+
$stdout.puts Usage.new.content
|
|
65
38
|
end
|
|
66
39
|
end
|
|
67
40
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Space2underscore
|
|
4
|
+
# Converts spaces to underscores in branch names
|
|
5
|
+
class Converter
|
|
6
|
+
class << self
|
|
7
|
+
# Convert input to branch name with underscores
|
|
8
|
+
#
|
|
9
|
+
# @param input [Array<String>] Input words
|
|
10
|
+
# @return [String] Branch name with underscores
|
|
11
|
+
def convert(input)
|
|
12
|
+
return '' if input.empty?
|
|
13
|
+
|
|
14
|
+
if input.length == 1
|
|
15
|
+
# Single argument: "foo bar" -> "foo_bar"
|
|
16
|
+
input[0].strip.gsub(/\s+/, '_')
|
|
17
|
+
else
|
|
18
|
+
# Multiple arguments: ["foo", "bar"] -> "foo_bar"
|
|
19
|
+
input.join('_')
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Space2underscore
|
|
4
|
+
# Represents parsed command-line options
|
|
5
|
+
Options = Struct.new(:action, :input, :downcase, keyword_init: true)
|
|
6
|
+
|
|
7
|
+
# Parses command-line arguments into Options
|
|
8
|
+
class OptionsParser
|
|
9
|
+
CREATE_FLAGS = %w[-c --create].freeze
|
|
10
|
+
RAW_FLAGS = %w[-r --raw].freeze
|
|
11
|
+
ALL_FLAGS = (CREATE_FLAGS + RAW_FLAGS).freeze
|
|
12
|
+
|
|
13
|
+
ParseError = Class.new(ArgumentError)
|
|
14
|
+
|
|
15
|
+
class << self
|
|
16
|
+
# Parse argv into Options object
|
|
17
|
+
#
|
|
18
|
+
# @param argv [Array<String>] Command-line arguments
|
|
19
|
+
# @return [Options, nil] Parsed options or nil if empty
|
|
20
|
+
# @raise [ParseError] If arguments are invalid
|
|
21
|
+
def parse(argv)
|
|
22
|
+
return nil if argv.empty? # Triggers usage display
|
|
23
|
+
|
|
24
|
+
has_create = argv.any? { |arg| CREATE_FLAGS.include?(arg) }
|
|
25
|
+
has_raw = argv.any? { |arg| RAW_FLAGS.include?(arg) }
|
|
26
|
+
input = argv.reject { |arg| ALL_FLAGS.include?(arg) }
|
|
27
|
+
|
|
28
|
+
validate_input!(input)
|
|
29
|
+
|
|
30
|
+
Options.new(
|
|
31
|
+
action: has_create ? :create : :print,
|
|
32
|
+
input: input,
|
|
33
|
+
downcase: !has_raw # raw flag means preserve case
|
|
34
|
+
)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def validate_input!(input)
|
|
40
|
+
raise ParseError, 'Branch name is required' if input.empty?
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Space2underscore
|
|
4
|
+
# Prints branch names to stdout
|
|
5
|
+
class OutputPrinter
|
|
6
|
+
class << self
|
|
7
|
+
# Print branch name to stdout
|
|
8
|
+
#
|
|
9
|
+
# @param name [String] Branch name to print
|
|
10
|
+
# @return [void]
|
|
11
|
+
def print(name)
|
|
12
|
+
$stdout.puts name
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
data/lib/space2underscore.rb
CHANGED
|
@@ -7,8 +7,9 @@ end
|
|
|
7
7
|
require 'singleton'
|
|
8
8
|
|
|
9
9
|
require 'space2underscore/version'
|
|
10
|
-
require 'space2underscore/
|
|
11
|
-
require 'space2underscore/
|
|
12
|
-
require 'space2underscore/
|
|
10
|
+
require 'space2underscore/options_parser'
|
|
11
|
+
require 'space2underscore/converter'
|
|
12
|
+
require 'space2underscore/output_printer'
|
|
13
|
+
require 'space2underscore/branch_creator'
|
|
13
14
|
require 'space2underscore/usage'
|
|
14
15
|
require 'space2underscore/cli'
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: space2underscore
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.6.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- sachin21
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: bundler
|
|
@@ -70,16 +69,16 @@ dependencies:
|
|
|
70
69
|
name: rubocop
|
|
71
70
|
requirement: !ruby/object:Gem::Requirement
|
|
72
71
|
requirements:
|
|
73
|
-
- - "
|
|
72
|
+
- - "~>"
|
|
74
73
|
- !ruby/object:Gem::Version
|
|
75
|
-
version:
|
|
74
|
+
version: '1.0'
|
|
76
75
|
type: :development
|
|
77
76
|
prerelease: false
|
|
78
77
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
78
|
requirements:
|
|
80
|
-
- - "
|
|
79
|
+
- - "~>"
|
|
81
80
|
- !ruby/object:Gem::Version
|
|
82
|
-
version:
|
|
81
|
+
version: '1.0'
|
|
83
82
|
description: Change the space into underscore
|
|
84
83
|
email:
|
|
85
84
|
- sachin21dev@gmail.com
|
|
@@ -89,34 +88,26 @@ executables:
|
|
|
89
88
|
extensions: []
|
|
90
89
|
extra_rdoc_files: []
|
|
91
90
|
files:
|
|
92
|
-
- ".gitignore"
|
|
93
|
-
- ".rspec"
|
|
94
|
-
- ".rubocop.yml"
|
|
95
|
-
- ".travis.yml"
|
|
96
91
|
- CHANGELOG.md
|
|
97
|
-
- Gemfile
|
|
98
92
|
- MIT-LICENSE
|
|
99
93
|
- README.md
|
|
100
|
-
- Rakefile
|
|
101
94
|
- bin/s2u
|
|
102
95
|
- bin/space2underscore
|
|
103
96
|
- lib/space2underscore.rb
|
|
97
|
+
- lib/space2underscore/branch_creator.rb
|
|
104
98
|
- lib/space2underscore/cli.rb
|
|
105
|
-
- lib/space2underscore/
|
|
106
|
-
- lib/space2underscore/
|
|
107
|
-
- lib/space2underscore/
|
|
99
|
+
- lib/space2underscore/converter.rb
|
|
100
|
+
- lib/space2underscore/options_parser.rb
|
|
101
|
+
- lib/space2underscore/output_printer.rb
|
|
108
102
|
- lib/space2underscore/usage.rb
|
|
109
103
|
- lib/space2underscore/version.rb
|
|
110
104
|
- post_install_message.txt
|
|
111
|
-
- space2underscore.gemspec
|
|
112
|
-
- spec/space2underscore/printer_spec.rb
|
|
113
|
-
- spec/space2underscore/underscore_spec.rb
|
|
114
|
-
- spec/space2underscore/usage_spec.rb
|
|
115
|
-
- spec/spec_helper.rb
|
|
116
105
|
homepage: https://github.com/sachin21/space2underscore
|
|
117
106
|
licenses:
|
|
118
107
|
- MIT
|
|
119
|
-
metadata:
|
|
108
|
+
metadata:
|
|
109
|
+
bug_tracker_uri: https://github.com/sachin21/space2underscore/issues
|
|
110
|
+
source_code_uri: https://github.com/sachin21/space2underscore
|
|
120
111
|
post_install_message: |
|
|
121
112
|
..........................................................
|
|
122
113
|
__________________________________________________________
|
|
@@ -143,20 +134,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
143
134
|
requirements:
|
|
144
135
|
- - ">="
|
|
145
136
|
- !ruby/object:Gem::Version
|
|
146
|
-
version: 2.
|
|
137
|
+
version: 2.7.0
|
|
147
138
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
139
|
requirements:
|
|
149
140
|
- - ">="
|
|
150
141
|
- !ruby/object:Gem::Version
|
|
151
142
|
version: '0'
|
|
152
143
|
requirements: []
|
|
153
|
-
|
|
154
|
-
rubygems_version: 2.7.6
|
|
155
|
-
signing_key:
|
|
144
|
+
rubygems_version: 4.0.4
|
|
156
145
|
specification_version: 4
|
|
157
146
|
summary: Change the space into underscore
|
|
158
|
-
test_files:
|
|
159
|
-
- spec/space2underscore/printer_spec.rb
|
|
160
|
-
- spec/space2underscore/underscore_spec.rb
|
|
161
|
-
- spec/space2underscore/usage_spec.rb
|
|
162
|
-
- spec/spec_helper.rb
|
|
147
|
+
test_files: []
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/.rubocop.yml
DELETED
data/.travis.yml
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
language: ruby
|
|
2
|
-
|
|
3
|
-
rvm:
|
|
4
|
-
- 2.3.7
|
|
5
|
-
- 2.4.4
|
|
6
|
-
- 2.5.1
|
|
7
|
-
- ruby-head
|
|
8
|
-
|
|
9
|
-
before_install:
|
|
10
|
-
- gem install bundler
|
|
11
|
-
- rm -f .git/index.lock
|
|
12
|
-
|
|
13
|
-
script: "bundle exec rake spec:with_coveralls"
|
|
14
|
-
|
|
15
|
-
notifications:
|
|
16
|
-
email: false
|
|
17
|
-
slack: sachin21dev:3pEyff2UFnoCgl4NI0uxbsER
|
data/Gemfile
DELETED
data/Rakefile
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
gem_helper = Bundler::GemHelper.new
|
|
9
|
-
|
|
10
|
-
desc "Create tag #{gem_helper.send(:version_tag)}"
|
|
11
|
-
task :tag do
|
|
12
|
-
gem_helper.send(:tag_version) unless gem_helper.send(:already_tagged?)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
task default: :spec
|
|
16
|
-
|
|
17
|
-
namespace :spec do
|
|
18
|
-
desc 'Run RSpec with Coveralls'
|
|
19
|
-
task :with_coveralls do
|
|
20
|
-
ENV['COVERALLS'] = 'true'
|
|
21
|
-
Rake::Task['spec'].execute
|
|
22
|
-
end
|
|
23
|
-
end
|
data/bin/s2u
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Space2underscore
|
|
4
|
-
class Executor
|
|
5
|
-
include Singleton
|
|
6
|
-
|
|
7
|
-
def run_with_raw(underscore_include_sentence)
|
|
8
|
-
run underscore_include_sentence
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def run_with_downcase(underscore_include_sentence)
|
|
12
|
-
run underscore_include_sentence.downcase
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
def run(sentence)
|
|
18
|
-
exit system "git checkout -b #{sentence}"
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Space2underscore
|
|
4
|
-
class Printer
|
|
5
|
-
include Singleton
|
|
6
|
-
|
|
7
|
-
def run_with_raw(branch)
|
|
8
|
-
run branch
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def run_with_downcase(branch)
|
|
12
|
-
run branch.downcase
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
private
|
|
16
|
-
|
|
17
|
-
def run(branch)
|
|
18
|
-
$stdout.puts branch
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Space2underscore
|
|
4
|
-
class Underscore
|
|
5
|
-
def initialize(sentence)
|
|
6
|
-
@sentence = sentence
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def convert
|
|
10
|
-
if @sentence.length == 1
|
|
11
|
-
@sentence[0].strip.gsub(/\s/, '_')
|
|
12
|
-
else
|
|
13
|
-
@sentence.join('_')
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
data/space2underscore.gemspec
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
lib = File.expand_path('../lib', __FILE__)
|
|
4
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
|
-
require 'space2underscore/version'
|
|
6
|
-
|
|
7
|
-
Gem::Specification.new do |spec|
|
|
8
|
-
spec.name = 'space2underscore'
|
|
9
|
-
spec.version = Space2underscore::VERSION
|
|
10
|
-
spec.authors = ['sachin21']
|
|
11
|
-
spec.email = ['sachin21dev@gmail.com']
|
|
12
|
-
spec.description = 'Change the space into underscore'
|
|
13
|
-
spec.summary = 'Change the space into underscore'
|
|
14
|
-
spec.homepage = 'https://github.com/sachin21/space2underscore'
|
|
15
|
-
spec.license = 'MIT'
|
|
16
|
-
|
|
17
|
-
spec.files = `git ls-files`.split($RS)
|
|
18
|
-
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
19
|
-
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
20
|
-
spec.require_paths = ['lib']
|
|
21
|
-
spec.required_ruby_version = '>= 2.3.0'
|
|
22
|
-
|
|
23
|
-
spec.post_install_message = File.read('post_install_message.txt')
|
|
24
|
-
|
|
25
|
-
spec.add_development_dependency 'bundler'
|
|
26
|
-
spec.add_development_dependency 'rake'
|
|
27
|
-
spec.add_development_dependency 'rspec'
|
|
28
|
-
spec.add_development_dependency 'pry'
|
|
29
|
-
spec.add_development_dependency 'rubocop', '< 0.49.0'
|
|
30
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
|
|
5
|
-
describe Space2underscore::Printer do
|
|
6
|
-
let(:branch) { 'FOO_bar' }
|
|
7
|
-
|
|
8
|
-
describe '#run_with_raw' do
|
|
9
|
-
subject { -> { described_class.instance.run_with_raw(branch) } }
|
|
10
|
-
|
|
11
|
-
it { is_expected.to output(/FOO_bar/).to_stdout }
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
describe '#run_with_downcase' do
|
|
15
|
-
subject { -> { described_class.instance.run_with_downcase(branch) } }
|
|
16
|
-
|
|
17
|
-
it { is_expected.to output(/foo_bar/).to_stdout }
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
require 'open3'
|
|
5
|
-
|
|
6
|
-
describe Space2underscore::Underscore do
|
|
7
|
-
describe '#convert' do
|
|
8
|
-
subject { described_class.new(argument).convert }
|
|
9
|
-
|
|
10
|
-
context 'when number of argument is one' do
|
|
11
|
-
let(:argument) { ['foo bar'] }
|
|
12
|
-
|
|
13
|
-
it { is_expected.to include('_') }
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
context 'when number of argument is many' do
|
|
17
|
-
let(:argument) { %w[foo bar] }
|
|
18
|
-
|
|
19
|
-
it { is_expected.to include('_') }
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'space2underscore'
|
|
4
|
-
|
|
5
|
-
if ENV['COVERALLS']
|
|
6
|
-
require 'coveralls'
|
|
7
|
-
Coveralls.wear!
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
Bundler.setup
|
|
11
|
-
|
|
12
|
-
RSpec.configure do |config|
|
|
13
|
-
config.order = 'random'
|
|
14
|
-
config.expect_with :rspec do |rspec|
|
|
15
|
-
rspec.syntax = :expect
|
|
16
|
-
end
|
|
17
|
-
end
|