space2underscore 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '09dc850870dd86b0335f6b5e3ca1e4d7b80af677'
4
- data.tar.gz: 4d33ef051ac1a64ebbeeeff3502998bfc138db59
3
+ metadata.gz: 47e87d5fef3cbf63b644d8718f6b5b4a6ac600b8
4
+ data.tar.gz: 3b93e888a49904995689e2eeacc17f552aacfc86
5
5
  SHA512:
6
- metadata.gz: 5963793b19ee2a4fb18384ca387a4a555db2ab6e35bfa5e1e0eaae77e10f456556e804fb4c1d9ca56f1c9c78b2ff4bc08aad46dca7cd3c22d8b30513e19355e0
7
- data.tar.gz: bc9f85ad75a939cb5165c11c48f5c004dae21709aec5d401d20ba5c0cf47dbdeee328a17ebc789f5fad1633bc0cb1f7952fffb4d1c4086905aecc1f44715d3b2
6
+ metadata.gz: 8044f50d77379b6c448c545e34a5d80d4939bd40b1527d34b5d50d45c4e794cd64334cd14ab78a1d270014392b33a3761cc01a59116203aeaac18e4e63884233
7
+ data.tar.gz: 0f6dc1b4eae1536a67a9ee18fce5e8e666cfe09c7f68f3e63a797ec3bed32ed6522fd2f4cd8ae3e36cb7d73aa9c817bdf0dfb06aeefbdbe2515ceef023717dd9
data/.gitignore CHANGED
@@ -3,7 +3,6 @@
3
3
  .bundle
4
4
  .config
5
5
  .yardoc
6
- Gemfile.lock
7
6
  InstalledFiles
8
7
  _yardoc
9
8
  coverage
@@ -16,3 +15,4 @@ test/tmp
16
15
  test/version_tmp
17
16
  tmp
18
17
  /vendor
18
+ Gemfile.lock
@@ -3,3 +3,6 @@ AllCops:
3
3
 
4
4
  Exclude:
5
5
  - 'vendor/bundle/**/*'
6
+
7
+ Style/Documentation:
8
+ Enabled: false
@@ -1,5 +1,16 @@
1
1
  # Space2underscore Change Log
2
2
 
3
+ ## v0.5.2
4
+ - Refactor methods in space2underscore.
5
+ - Refactor examples for space2underscore.
6
+ - Add an option for raw.
7
+
8
+ ### Security Changes
9
+ - Lock the RuboCop version over `0.49.0`.
10
+
11
+ ## v0.5.1
12
+ - Fix a bug where failed to print usage.
13
+
3
14
  ## v0.5.0
4
15
  - Add a task for tagging
5
16
  - Add tests for bins
data/README.md CHANGED
@@ -19,7 +19,7 @@ From the command line:
19
19
  ### 1. e.g. Create the new branch
20
20
 
21
21
  ```
22
- $ space2underscore new branch -c
22
+ $ s2u new branch -c
23
23
  => Switched to a new branch 'new_branch’
24
24
  ```
25
25
 
@@ -28,18 +28,11 @@ Run with `--create` or `-c` options.
28
28
  ### 2. e.g. Rename the already created a branch
29
29
 
30
30
  ```
31
- $ git branch -m $(space2underscore renamed branch)
31
+ $ git branch -m $(s2u renamed branch)
32
32
  ```
33
33
 
34
- When option is nothing, space2underscore has outputted to the standard output.
35
-
36
- ## Shorthand
37
-
38
- A shorthand alias for space2underscore can also be used.
39
-
40
- ```
41
- s2u new branch
42
- ```
34
+ ## !! Cation !!
35
+ This is a command line tool. So DO NOT include all modules because it uses `system` command. So crackers will be attacking your application.
43
36
 
44
37
  ## Credits
45
38
  - Help information based on [@motemen's ghq](https://github.com/motemen/ghq)
data/bin/s2u CHANGED
@@ -2,21 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'space2underscore'
5
- require 'pry'
6
5
 
7
- CREATE_FLAGS = %w(-c --create).freeze
8
-
9
- args = ARGV.reject { |arg| CREATE_FLAGS.include?(arg) }
10
- convert_flag = ARGV.select { |arg| CREATE_FLAGS.include?(arg) }
11
- underscore_include_sentence = Space2underscore.convert(args)
12
-
13
- if ARGV.empty?
14
- puts Space2underscore.usage
15
- exit
16
- end
17
-
18
- if convert_flag.empty?
19
- puts underscore_include_sentence
20
- else
21
- Space2underscore.create_new_branch(underscore_include_sentence)
22
- end
6
+ Space2underscore::Cli.new(ARGV).start
@@ -2,21 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'space2underscore'
5
- require 'pry'
6
5
 
7
- CREATE_FLAGS = %w(-c --create).freeze
8
-
9
- args = ARGV.reject { |arg| CREATE_FLAGS.include?(arg) }
10
- convert_flag = ARGV.select { |arg| CREATE_FLAGS.include?(arg) }
11
- underscore_include_sentence = Space2underscore.convert(args)
12
-
13
- if ARGV.empty?
14
- puts Space2underscore.usage
15
- exit
16
- end
17
-
18
- if convert_flag.empty?
19
- puts underscore_include_sentence
20
- else
21
- Space2underscore.create_new_branch(underscore_include_sentence)
22
- end
6
+ Space2underscore::Cli.new(ARGV).start
@@ -1,37 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'space2underscore/version'
4
-
5
3
  # This is the main functions.
6
4
  module Space2underscore
7
- MESSAGE = <<-EOF.chomp
8
- NAME:
9
- space2underscore - Change the space into underscore
10
-
11
- USAGE:
12
- $ space2underscore new branch -c
13
- => Switched to the new branch 'new_branch’
14
-
15
- Or
16
-
17
- $ git branch -m $(space2underscore renamed branch)
18
-
19
- VERSION:
20
- #{Space2underscore::VERSION}
21
-
22
- OPTIONS:
23
- --create, -c create a new branch
24
- EOF
25
-
26
- def self.convert(argv)
27
- argv.length == 1 ? argv[0].strip.gsub(/\s/, '_') : argv.join('_')
28
- end
5
+ end
29
6
 
30
- def self.create_new_branch(underscore_include_sentence)
31
- system "git checkout -b #{underscore_include_sentence}"
32
- end
7
+ require 'space2underscore/version'
33
8
 
34
- def self.usage
35
- MESSAGE.gsub(' ', '')
36
- end
37
- end
9
+ require 'space2underscore/executor'
10
+ require 'space2underscore/printer'
11
+ require 'space2underscore/underscore'
12
+ require 'space2underscore/usage'
13
+ require 'space2underscore/cli'
@@ -0,0 +1,46 @@
1
+ module Space2underscore
2
+ class Cli
3
+ CREATE_FLAGS = %w[-c --create].freeze
4
+ RAW_FLAGS = %w[-r --raw].freeze
5
+
6
+ FLAGS = [CREATE_FLAGS, RAW_FLAGS].flatten.freeze
7
+
8
+ OptionParseError = Class.new(ArgumentError)
9
+
10
+ def initialize(argv)
11
+ @argv = argv
12
+ @underscore_include_branch = Underscore.new(branch).convert
13
+ end
14
+
15
+ def start
16
+ $stdout.puts Usage.new.content && exit if @argv.empty?
17
+
18
+ case
19
+ when included?(CREATE_FLAGS) && included?(RAW_FLAGS)
20
+ Executor.new(@underscore_include_branch).run_with_raw
21
+ when included?(CREATE_FLAGS) && not_included?(RAW_FLAGS)
22
+ Executor.new(@underscore_include_branch).run_with_downcase
23
+ when not_included?(CREATE_FLAGS) && included?(RAW_FLAGS)
24
+ Printer.instance.run_with_raw(@underscore_include_branch)
25
+ when not_included?(CREATE_FLAGS) && not_included?(RAW_FLAGS)
26
+ Printer.instance.run_with_downcase(@underscore_include_branch)
27
+ else
28
+ raise OptionParseError, 'Option is invalid format. It is only avaliable for `-c --create -d --downcase`'
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def branch
35
+ @argv.reject { |arg| FLAGS.include?(arg) }
36
+ end
37
+
38
+ def included?(flags)
39
+ @argv.any? { |arg| flags.include?(arg) }
40
+ end
41
+
42
+ def not_included?(flags)
43
+ !included?(flags)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,21 @@
1
+ module Space2underscore
2
+ class Executor
3
+ def initialize(underscore_include_sentence)
4
+ @underscore_include_sentence = underscore_include_sentence
5
+ end
6
+
7
+ def run_with_raw
8
+ run @underscore_include_sentence
9
+ end
10
+
11
+ def run_with_downcase
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
@@ -0,0 +1,21 @@
1
+ require 'singleton'
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
@@ -0,0 +1,15 @@
1
+ module Space2underscore
2
+ class Underscore
3
+ def initialize(sentence)
4
+ @sentence = sentence
5
+ end
6
+
7
+ def convert
8
+ if @sentence.length == 1
9
+ @sentence[0].strip.gsub(/\s/, '_')
10
+ else
11
+ @sentence.join('_')
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ module Space2underscore
2
+ class Usage
3
+ MESSAGE = <<-EOF.chomp
4
+ NAME:
5
+ space2underscore - Change the space into underscore
6
+
7
+ USAGE:
8
+ $ space2underscore new branch -c
9
+ => Switched to the new branch 'new_branch’
10
+
11
+ Or
12
+
13
+ $ git branch -m $(space2underscore renamed branch)
14
+
15
+ VERSION:
16
+ #{Space2underscore::VERSION}
17
+
18
+ OPTIONS:
19
+ --create, -c create a new branch
20
+ EOF
21
+
22
+ def content
23
+ MESSAGE.gsub(' ', '')
24
+ end
25
+ end
26
+ end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # This module holds the Space2underscore version information.
4
4
  module Space2underscore
5
- VERSION = '0.5.1'
5
+ VERSION = '0.5.2'
6
6
  end
@@ -21,9 +21,9 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.post_install_message = File.read('post_install_message.txt')
23
23
 
24
- spec.add_development_dependency 'bundler', '~> 1.3'
24
+ spec.add_development_dependency 'bundler'
25
25
  spec.add_development_dependency 'rake'
26
26
  spec.add_development_dependency 'rspec'
27
27
  spec.add_development_dependency 'pry'
28
- spec.add_development_dependency 'rubocop'
28
+ spec.add_development_dependency 'rubocop', '< 0.49.0'
29
29
  end
@@ -0,0 +1,19 @@
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
@@ -0,0 +1,22 @@
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
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Space2underscore::Usage do
6
+ subject { described_class.new.content }
7
+
8
+ it { is_expected.to be_a String }
9
+ it { is_expected.not_to be_empty }
10
+ end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'bundler/setup'
4
3
  require 'space2underscore'
5
4
 
6
5
  if ENV['COVERALLS']
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: space2underscore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - sachin21
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-21 00:00:00.000000000 Z
11
+ date: 2017-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.3'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.3'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: rubocop
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "<"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.49.0
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "<"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 0.49.0
83
83
  description: Change the space into underscore
84
84
  email:
85
85
  - sachin21.developer@gmail.com
@@ -101,10 +101,17 @@ files:
101
101
  - bin/s2u
102
102
  - bin/space2underscore
103
103
  - lib/space2underscore.rb
104
+ - lib/space2underscore/cli.rb
105
+ - lib/space2underscore/executor.rb
106
+ - lib/space2underscore/printer.rb
107
+ - lib/space2underscore/underscore.rb
108
+ - lib/space2underscore/usage.rb
104
109
  - lib/space2underscore/version.rb
105
110
  - post_install_message.txt
106
111
  - space2underscore.gemspec
107
- - spec/space2underscore_spec.rb
112
+ - spec/space2underscore/printer_spec.rb
113
+ - spec/space2underscore/underscore_spec.rb
114
+ - spec/space2underscore/usage_spec.rb
108
115
  - spec/spec_helper.rb
109
116
  homepage: https://github.com/sachin21/space2underscore
110
117
  licenses:
@@ -144,10 +151,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
151
  version: '0'
145
152
  requirements: []
146
153
  rubyforge_project:
147
- rubygems_version: 2.6.10
154
+ rubygems_version: 2.6.13
148
155
  signing_key:
149
156
  specification_version: 4
150
157
  summary: Change the space into underscore
151
158
  test_files:
152
- - spec/space2underscore_spec.rb
159
+ - spec/space2underscore/printer_spec.rb
160
+ - spec/space2underscore/underscore_spec.rb
161
+ - spec/space2underscore/usage_spec.rb
153
162
  - spec/spec_helper.rb
@@ -1,91 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'open3'
5
-
6
- describe Space2underscore do
7
- let(:branch_name) { 'foo_bar' }
8
- let(:hidden) { '&> /dev/null' }
9
-
10
- describe '.convert' do
11
- it 'returns underscore included in string' do
12
- expect(Space2underscore.convert(['foo bar'])).to include('_')
13
- expect(Space2underscore.convert(%w(foo bar))).to include('_')
14
- end
15
- end
16
-
17
- def checkout_master
18
- execute_command('git checkout master')
19
- end
20
-
21
- def delete_branch
22
- execute_command("git branch -D #{branch_name}")
23
- end
24
-
25
- def create_branch
26
- execute_command("git branch #{branch_name}")
27
- end
28
-
29
- def execute_command(command)
30
- system("#{command} #{hidden}")
31
- end
32
-
33
- describe '.create_new_branch' do
34
- before do
35
- checkout_master
36
- delete_branch
37
- end
38
-
39
- after do
40
- checkout_master
41
- delete_branch
42
- end
43
-
44
- it 'creates the new branch' do
45
- expect(Space2underscore.create_new_branch(branch_name)).to eq true
46
- end
47
- end
48
-
49
- describe '.usage' do
50
- it 'returns String class' do
51
- expect(Space2underscore.usage).to be_a(String)
52
- end
53
-
54
- it 'does not return an blank string does' do
55
- expect(Space2underscore.usage).not_to be_nil
56
- end
57
- end
58
-
59
- describe 'bin' do
60
- let(:argument1) { 'hoge' }
61
- let(:argument2) { 'fuga' }
62
- let(:result) { Open3.capture2(bin, argument1, argument2) }
63
- subject(:output) { result[0] }
64
- subject(:status) { result[1] }
65
-
66
- shared_examples_for 'output' do
67
- it 'returns underscore included in string' do
68
- expect(output).to eq "hoge_fuga\n"
69
- end
70
- end
71
-
72
- shared_examples_for 'status' do
73
- it 'returns underscore included in string' do
74
- expect(status.success?).to be true
75
- end
76
- end
77
-
78
- context 'with Space2underscore' do
79
- let(:bin) { File.join('bin', 's2u') }
80
-
81
- it_behaves_like 'output'
82
- it_behaves_like 'status'
83
- end
84
- context 'with s2u' do
85
- let(:bin) { File.join('bin', 'space2underscore') }
86
-
87
- it_behaves_like 'output'
88
- it_behaves_like 'status'
89
- end
90
- end
91
- end