rocket_api 0.0.1.5 → 0.0.1.6

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: 66e656376317222d804ebacb21b4402571ef5e304f87ca87eb27ec7ef2038b1b
4
- data.tar.gz: bf4906885176567fe040a2d7d72331f777527ed65b24517ae1f72fc9953cde79
3
+ metadata.gz: a1022fcc23b0400dc2dd32da344613ddbf781a28943eeed0f4fb7a017ef713a1
4
+ data.tar.gz: c6d6eb54cdc3c48b5aaf1ca64844d79767ddd05c182a2275196ee5e61b41785b
5
5
  SHA512:
6
- metadata.gz: 74b87e08dcf1c9de14186e18f6334d87e6bf413502e8fe3529eec79016de1cba56337fe6ff6621bf515d370aed592aa1ac4df847535ad6de624381961d088ecc
7
- data.tar.gz: de29ccd3ef2489e14b641a0e65adc9e9625cc472b54f0588b0c3671a7079791ef6e0b4b56dc7b5a07b171de3e0db4a76762ed159258876f79e6ff143a92ab430
6
+ metadata.gz: 65310b3e37e9d32996b8f307d9eb879fb712b24880522e6eb65330ac9063d1029bd5f7eda3b8c3d4421c858f8d4065e962d75647196347ae18acb2110776733f
7
+ data.tar.gz: 57a82a3489ffe10a8d32a4831bc803ec45e0bc1271dcca93695af43ac497cc1b51969e105f4a42cd36cbb2e2eb5a1090627469914ba599cf246397de645aafb7
data/README.md CHANGED
@@ -13,6 +13,8 @@ gem 'rubocop' '1.26'
13
13
  gem install rocket_api
14
14
  ```
15
15
  ## How it works:
16
- ```sh
17
- rocket_api init gem name_gem
16
+ ```sh
17
+ In working directory:
18
+
19
+ user@bulkas ~/gem/new_dir rocket_api init gem name_gem
18
20
  ```
data/bin/rocket_api CHANGED
@@ -2,25 +2,27 @@
2
2
 
3
3
  require "rocket_api"
4
4
 
5
- base_command = ARGV[0]
6
- sub_command = ARGV[1]
7
- project_name = ARGV[2]
5
+ base_command = ARGV[0]&.gsub(RocketApi::REGEXP_VALID, '')&.downcase
6
+ sub_command = ARGV[1]&.gsub(RocketApi::REGEXP_VALID, '')&.downcase
7
+ project_name = ARGV[2]&.gsub(RocketApi::REGEXP_VALID, '')&.downcase
8
8
 
9
- case base_command
10
- when RocketApi::INIT
11
- case sub_command
12
- when RocketApi::BASE
13
- # TODO: implement me
14
- when RocketApi::GEM
15
- begin
16
- RocketApi::RocketCommands.init_gem_dir
17
- RocketApi::RocketCommands.init_gem_files project_name&.downcase
18
- rescue RocketApi::Error => e
19
- puts "Init directory error: #{e.message}"
9
+ if [base_command, sub_command, project_name].map(&:nil?).any?
10
+ puts RocketApi::WRONG_RESPONSE
11
+ return
12
+ end
13
+
14
+ case
15
+ when RocketApi::AVAILABLE_COMMANDS.keys.include?(base_command&.to_sym)
16
+ if RocketApi::AVAILABLE_COMMANDS[base_command&.to_sym].keys.include?(sub_command&.to_sym)
17
+ RocketApi::AVAILABLE_COMMANDS[base_command&.to_sym][sub_command&.to_sym].each do |command|
18
+ RocketApi::RocketCommands.send(command, project_name: project_name)
19
+ rescue RocketApi::Error => e
20
+ puts "#{RocketApi::INIT_DIR_ERROR} #{e.message}"
21
+ return
20
22
  end
21
23
  else
22
- puts RocketApi::WRONG_ANSWER
24
+ puts RocketApi::WRONG_RESPONSE
23
25
  end
24
26
  else
25
- puts RocketApi::WRONG_ANSWER
27
+ puts RocketApi::WRONG_RESPONSE
26
28
  end
@@ -16,7 +16,10 @@ module RocketApi
16
16
  def init_gems_main_file!(name)
17
17
  file_name = "lib/#{name}.rb"
18
18
  text = "class #{class_name_camel(name)}; end"
19
- create_single_file(file_name, text)
19
+ create_single_file(
20
+ file_name,
21
+ text
22
+ )
20
23
  end
21
24
 
22
25
  # @param [String] name
@@ -0,0 +1,22 @@
1
+ module RocketApi
2
+ module Commands
3
+ module Helper
4
+ def init_bin!(name)
5
+ dir_name = "bin/#{name}"
6
+ create_single_file(
7
+ dir_name,
8
+ "",
9
+ exe: true
10
+ )
11
+ end
12
+
13
+ def init_gitignore!
14
+ file_name = ".gitignore"
15
+ create_single_file(
16
+ file_name,
17
+ gitignore_text
18
+ )
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,19 +1,28 @@
1
1
  module RocketApi
2
+ # Valid input
3
+ REGEXP_VALID = /[^0-9A-Za-z_-]/.freeze
4
+
2
5
  # Dirs map
3
6
  GEM_PROJECTS_DIR = %w[bin lib test].freeze
7
+ AVAILABLE_COMMANDS = {
8
+ init: {
9
+ gem: %w[init_gem_dir init_gem_files]
10
+ }
11
+ }.freeze
4
12
 
5
13
  # Ping
6
14
  PONG = "PONG".freeze
7
15
 
8
16
  # Commands
9
- INIT = "init".freeze
10
17
  BASE = "base".freeze
11
18
  GEM = "gem".freeze
12
19
 
13
20
  # Answers
21
+ INIT_DIR_ERROR = "Init directory error".freeze
22
+ GEM_DETECTED = "another one gem exist".freeze
14
23
  FOLDER_EXIST = "folder exist:".freeze
15
24
  FILE_EXIST = "file already exist:".freeze
16
- WRONG_ANSWER = "Wrong command".freeze
25
+ WRONG_RESPONSE = "Wrong command".freeze
17
26
  EMPTY_NAME = "Project name is empty".freeze
18
27
  INIT_FAIL = "Init action fail:".freeze
19
28
  CREATE_FAILED = "Create failed:".freeze
@@ -1,11 +1,8 @@
1
1
  module RocketApi
2
- # ...
3
2
  # Base error
4
3
  class Error < StandardError; end
5
- # ...
6
4
  # Raise in case of dir creation error
7
5
  class CreateDirError < Error; end
8
- # ...
9
6
  # Raise in case of file creation error
10
7
  class InitFilesError < Error; end
11
8
  end
@@ -1,6 +1,7 @@
1
1
  require "rocket_api/commands/files"
2
2
  require "rocket_api/commands/dirs"
3
3
  require "rocket_api/commands/gems_dir"
4
+ require "rocket_api/commands/helper"
4
5
  require "rocket_api/library/gem_repo_plain_text"
5
6
 
6
7
  module RocketApi
@@ -8,10 +9,13 @@ module RocketApi
8
9
  extend RocketApi::Commands::Files
9
10
  extend RocketApi::Commands::Dirs
10
11
  extend RocketApi::Commands::GemsDir
12
+ extend RocketApi::Commands::Helper
11
13
  extend RocketApi::Library::GemRepoPlainText
12
14
 
13
15
  # @raise [RocketApi::CreateDirError]
14
- def self.init_gem_dir
16
+ def self.init_gem_dir(**_options)
17
+ raise GEM_DETECTED unless Dir.glob("*.gemspec").empty?
18
+
15
19
  create_repo(RocketApi::GEM_PROJECTS_DIR)
16
20
  rescue StandardError => e
17
21
  raise RocketApi::CreateDirError,
@@ -21,9 +25,10 @@ module RocketApi
21
25
  # @param [String] project_name
22
26
  # ...
23
27
  # @raise [RocketApi::InitFilesError] error
24
- def self.init_gem_files(project_name)
25
- raise RocketApi::EMPTY_NAME if project_name.nil?
28
+ def self.init_gem_files(**options)
29
+ raise RocketApi::EMPTY_NAME if options[:project_name].nil?
26
30
 
31
+ project_name = options[:project_name]
27
32
  init_bin!(project_name)
28
33
  init_gemspec!(project_name)
29
34
  init_gems_main_file!(project_name)
@@ -33,22 +38,5 @@ module RocketApi
33
38
  raise RocketApi::InitFilesError,
34
39
  "#{RocketApi::INIT_FAIL} #{e.message}"
35
40
  end
36
-
37
- def self.init_bin!(name)
38
- dir_name = "bin/#{name}"
39
- create_single_file(
40
- dir_name,
41
- "",
42
- exe: true
43
- )
44
- end
45
-
46
- def self.init_gitignore!
47
- file_name = ".gitignore"
48
- create_single_file(
49
- file_name,
50
- gitignore_text
51
- )
52
- end
53
41
  end
54
42
  end
@@ -1,3 +1,3 @@
1
1
  module RocketApi
2
- VERSION = "0.0.1.5".freeze
2
+ VERSION = "0.0.1.6".freeze
3
3
  end
data/lib/rocket_api.rb CHANGED
@@ -4,4 +4,5 @@ require "rocket_api/errors"
4
4
  require "rocket_api/commands/files"
5
5
  require "rocket_api/commands/dirs"
6
6
  require "rocket_api/commands/gems_dir"
7
+ require "rocket_api/commands/helper"
7
8
  require "rocket_api/library/gem_repo_plain_text"
data/rocket_api.gemspec CHANGED
@@ -1,26 +1,26 @@
1
1
  lib = File.expand_path("lib", __dir__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
- require 'English'
5
- require 'rocket_api/version'
4
+ require "English"
5
+ require "rocket_api/version"
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.specification_version = 2 if s.respond_to? :specification_version=
9
9
  if s.respond_to? :required_rubygems_version=
10
- s.required_rubygems_version = Gem::Requirement.new('>= 0')
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0")
11
11
  end
12
- s.rubygems_version = '2.7'
13
- s.required_ruby_version = '>=2.2'
14
- s.name = 'rocket_api'
12
+ s.rubygems_version = "2.7"
13
+ s.required_ruby_version = ">=2.2"
14
+ s.name = "rocket_api"
15
15
  s.version = RocketApi::VERSION
16
- s.executables << 'rocket_api'
17
- s.license = 'MIT'
18
- s.summary = 'Create working structure'
19
- s.description = 'Create working structure.'
20
- s.authors = ['Ilya Kondratev']
21
- s.email = 'ilyafulleveline@gmail.com'
22
- s.homepage = 'https://github.com/ikondratev/rocket_api'
16
+ s.executables << "rocket_api"
17
+ s.license = "MIT"
18
+ s.summary = "Create gem project structure and init main files in directory"
19
+ s.description = "Initialize directory with gem's structure.\n Include:\n*.gemspec\nlib/version\n.gitignore\nbin/*"
20
+ s.authors = ["Ilya Kondratev"]
21
+ s.email = "ilyafulleveline@gmail.com"
22
+ s.homepage = "https://github.com/ikondratev/rocket_api"
23
23
  s.files = `git ls-files`.split($RS)
24
- s.add_dependency 'rubocop', '~> 1.26'
25
- s.add_dependency 'rubocop-rake'
24
+ s.add_dependency "rubocop", "~> 1.26"
25
+ s.add_dependency "rubocop-rake"
26
26
  end
data/test/test_version.rb CHANGED
@@ -4,6 +4,6 @@ require 'rocket_api/version'
4
4
  class TestVersion < Minitest::Test
5
5
  include RocketApi
6
6
  def test_ping
7
- assert_equal("0.0.1.5", RocketApi::VERSION)
7
+ assert_equal("0.0.1.6", RocketApi::VERSION)
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rocket_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.5
4
+ version: 0.0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ilya Kondratev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-17 00:00:00.000000000 Z
11
+ date: 2022-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubocop
@@ -38,7 +38,13 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description: Create working structure.
41
+ description: |-
42
+ Initialize directory with gem's structure.
43
+ Include:
44
+ *.gemspec
45
+ lib/version
46
+ .gitignore
47
+ bin/*
42
48
  email: ilyafulleveline@gmail.com
43
49
  executables:
44
50
  - rocket_api
@@ -57,6 +63,7 @@ files:
57
63
  - lib/rocket_api/commands/dirs.rb
58
64
  - lib/rocket_api/commands/files.rb
59
65
  - lib/rocket_api/commands/gems_dir.rb
66
+ - lib/rocket_api/commands/helper.rb
60
67
  - lib/rocket_api/constants.rb
61
68
  - lib/rocket_api/errors.rb
62
69
  - lib/rocket_api/library/gem_repo_plain_text.rb
@@ -86,5 +93,5 @@ requirements: []
86
93
  rubygems_version: 3.1.4
87
94
  signing_key:
88
95
  specification_version: 2
89
- summary: Create working structure
96
+ summary: Create gem project structure and init main files in directory
90
97
  test_files: []