rocket_api 0.0.1.9 → 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: 0300050a0bdc48251533068b06db4638fff1ae13f85fa315e6832444fb7763d5
4
- data.tar.gz: 2e217624a32f29abe47e3a97bc56d1af870c058bf2784c7cefe8eeca19675c66
3
+ metadata.gz: 97b2320edad5eb7b7b372adaa940695243cad6d763f015e0b808b97fa481c013
4
+ data.tar.gz: 1a8e5e39585f85c3936188bd1124409111d88b884daeb063224526edbb250b66
5
5
  SHA512:
6
- metadata.gz: bbf4749e0e87c43f033d6adb7bd06ba5a59ba83a332dd23cf96a0de58b1a790f585cc372e722a91d224c13a6ce1fc573024e6864de7904a0b168a656e6084635
7
- data.tar.gz: 198073b10660fa5b715949cd2ce815bef63daf938c78c1ca9b991fdacbdd1e99e441eb0ffa54049ee6166c26d25f5c741cb56de22006f2e9129600a94a1c0a44
6
+ metadata.gz: 34407638e02527001e3c0e454fe68cff4b2b63f634c81600c0acccc24967fdd619d6c5584ad274d485f0a4a7a951a5dc423583104a0fc5ff56fd9bf3cbe9d923
7
+ data.tar.gz: 0e420cbec9513e546e99a6bf53a44eb6b7c9fa8cb3c5c841d9b76d83faffd85df3b0b738feaeb0787ded74b17bd77e1c3c63e10db3af7c797a471c6fd8366b55
data/bin/rocket_api CHANGED
@@ -2,32 +2,22 @@
2
2
 
3
3
  require "rocket_api"
4
4
 
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
5
+ include RocketApi::Validation
6
+ include RocketApi::Lib
8
7
 
9
- if [base_command, sub_command, project_name].map(&:nil?).any?
10
- puts RocketApi::WRONG_RESPONSE
11
- return
12
- end
8
+ base_command, sub_command, project_name = ARGV.map{|cmd| cmd&.gsub(RocketApi::REGEXP_VALID, '')&.downcase }
13
9
 
14
- unless RocketApi::CHECK_APPS.map { |p| Dir.glob(p) }.flatten.empty?
15
- puts RocketApi::APP_DETECTED
16
- return
17
- end
10
+ safe("RocketApi") do
11
+ validate_commands(base_command, sub_command, project_name)
12
+ available_to_init?
13
+
14
+ raise RocketApi::WRONG_RESPONSE unless RocketApi::AVAILABLE_COMMANDS.keys.include?(base_command)
18
15
 
19
- case
20
- when RocketApi::AVAILABLE_COMMANDS.keys.include?(base_command)
21
16
  if RocketApi::AVAILABLE_COMMANDS[base_command].keys.include?(sub_command)
22
17
  RocketApi::AVAILABLE_COMMANDS[base_command][sub_command].each do |key, collection|
23
18
  RocketApi::RocketCommands.send(key, collection: collection, project_name: project_name )
24
- rescue RocketApi::Error => e
25
- puts "#{RocketApi::INIT_DIR_ERROR} #{e.message}"
26
- return
27
19
  end
28
20
  else
29
- puts RocketApi::WRONG_RESPONSE
21
+ raise RocketApi::WRONG_RESPONSE
30
22
  end
31
- else
32
- puts RocketApi::WRONG_RESPONSE
33
23
  end
@@ -0,0 +1,10 @@
1
+ module RocketApi
2
+ module Commands
3
+ module BotDirs
4
+ # @param [String] _name
5
+ def bot_version!(_name)
6
+ # TODO: Implement me
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,6 +1,11 @@
1
1
  module RocketApi
2
2
  module Commands
3
3
  module Helper
4
+ # @param [String] name
5
+ def readme!(name)
6
+ create_single_file("README.md", readme_text(name))
7
+ end
8
+
4
9
  # @param [String] name
5
10
  def bin!(name)
6
11
  create_single_file("bin/#{name}", "", exe: true)
@@ -4,7 +4,7 @@ module RocketApi
4
4
  CHECK_APPS = %w[*.gemspec *.ru].freeze
5
5
 
6
6
  # Valid commands
7
- COMMANDS = { init: "init", gem: "gem", rack: "rack" }.freeze
7
+ COMMANDS = { init: "init", gem: "gem", rack: "rack", bot: "bot" }.freeze
8
8
 
9
9
  # Gem
10
10
  GEM_DIRS = %w[bin lib test].freeze
@@ -16,11 +16,17 @@ module RocketApi
16
16
  RACK_FILES = %w[rack_routes! rack_base_controller! rack_config_ru! gitignore! rack_app! rack_router! rack_initializers! rack_application! rack_gemfile!].freeze
17
17
  RACK_MAP = { init_dirs: RACK_DIRS, init_files: RACK_FILES }.freeze
18
18
 
19
+ # Bot
20
+ BOT_DIRS = %w[app bin config db test services].freeze
21
+ BOT_FILES = %w[readme! fake!].freeze
22
+ BOT_MAP = { init_dirs: BOT_DIRS, init_files: BOT_FILES }.freeze
23
+
19
24
  # Dirs map
20
25
  AVAILABLE_COMMANDS = {
21
26
  COMMANDS[:init] => {
22
27
  COMMANDS[:gem] => GEM_MAP,
23
- COMMANDS[:rack] => RACK_MAP
28
+ COMMANDS[:rack] => RACK_MAP,
29
+ COMMANDS[:bot] => BOT_MAP
24
30
  }
25
31
  }.freeze
26
32
 
@@ -35,8 +41,8 @@ module RocketApi
35
41
  WRONG_RESPONSE = "Wrong command".freeze
36
42
  EMPTY_NAME = "Project name is empty".freeze
37
43
  INIT_FAIL = "Init action fail:".freeze
38
- CREATE_FAILED = "Create failed:".freeze
39
- CREATE_SUCCESS = "Successfully created:".freeze
44
+ CREATE_FAILED = "Fail:".freeze
45
+ CREATE_SUCCESS = "Success:".freeze
40
46
 
41
47
  # Text
42
48
  TAB = "\s\s".freeze
@@ -7,4 +7,7 @@ module RocketApi
7
7
 
8
8
  # Raise in case of file creation error
9
9
  class InitFilesError < Error; end
10
+
11
+ # Raise in case of validation error
12
+ class ValidationError < Error; end
10
13
  end
@@ -0,0 +1,12 @@
1
+ module RocketApi
2
+ module Lib
3
+ # @param [String] category
4
+ def safe(category)
5
+ yield
6
+ rescue RocketApi::CreateDirError => e
7
+ puts "[#{category}] #{RocketApi::INIT_DIR_ERROR} #{e.message}"
8
+ rescue RocketApi::Error, StandardError => e
9
+ puts "[#{category}] #{e.message}"
10
+ end
11
+ end
12
+ end
@@ -20,23 +20,23 @@ module RocketApi
20
20
  "require 'English'",
21
21
  "require '#{name}/version'\n",
22
22
  "Gem::Specification.new do |s|",
23
- "\s\ss.specification_version = 2 if s.respond_to? :specification_version=",
24
- "\s\sif s.respond_to? :required_rubygems_version=",
25
- "\s\s\s\ss.required_rubygems_version = Gem::Requirement.new('>= 0')",
26
- "\s\send",
27
- "\s\ss.rubygems_version = 'RUBY_VERSION'",
28
- "\s\ss.required_ruby_version = 'RUBY_VERSION'",
29
- "\s\ss.name = '#{name}'",
30
- "\s\ss.version = #{module_name}::VERSION",
31
- "\s\ss.executables << '#{name}'",
32
- "\s\ss.summary = 'PUT_SUMMARY'",
33
- "\s\ss.description = 'PUT_DESCRIPTION'",
34
- "\s\ss.authors = ['AUTHOR']",
35
- "\s\ss.email = 'AUTHOR_MAIL'",
36
- "\s\ss.homepage = 'https://github.com/...'",
37
- "\s\ss.files = `git ls-files`.split($RS)",
38
- "\s\ss.add_dependency \"rubocop\"",
39
- "\s\ss.add_dependency \"rubocop-rake\"",
23
+ "#{TAB}s.specification_version = 2 if s.respond_to? :specification_version=",
24
+ "#{TAB}if s.respond_to? :required_rubygems_version=",
25
+ "#{DOUBLE_TAB}s.required_rubygems_version = Gem::Requirement.new('>= 0')",
26
+ "#{TAB}end",
27
+ "#{TAB}s.rubygems_version = 'RUBY_VERSION'",
28
+ "#{TAB}s.required_ruby_version = 'RUBY_VERSION'",
29
+ "#{TAB}s.name = '#{name}'",
30
+ "#{TAB}s.version = #{module_name}::VERSION",
31
+ "#{TAB}s.executables << '#{name}'",
32
+ "#{TAB}s.summary = 'PUT_SUMMARY'",
33
+ "#{TAB}s.description = 'PUT_DESCRIPTION'",
34
+ "#{TAB}s.authors = ['AUTHOR']",
35
+ "#{TAB}s.email = 'AUTHOR_MAIL'",
36
+ "#{TAB}s.homepage = 'https://github.com/...'",
37
+ "#{TAB}s.files = `git ls-files`.split($RS)",
38
+ "#{TAB}s.add_dependency \"rubocop\"",
39
+ "#{TAB}s.add_dependency \"rubocop-rake\"",
40
40
  "end"].join("\n")
41
41
  end
42
42
 
@@ -47,10 +47,10 @@ module RocketApi
47
47
  ["require 'minitest/autorun'",
48
48
  "require '#{name}/version'\n",
49
49
  "class TestVersion < Minitest::Test",
50
- "\s\sinclude #{module_name}\n",
51
- "\s\sdef test_ping",
52
- "\s\s\s\sassert_equal(\"0.0.1\", #{module_name}::VERSION)",
53
- "\s\send",
50
+ "#{TAB}include #{module_name}\n",
51
+ "#{TAB}def test_ping",
52
+ "#{DOUBLE_TAB}assert_equal(\"0.0.1\", #{module_name}::VERSION)",
53
+ "#{TAB}end",
54
54
  "end"].join("\n")
55
55
  end
56
56
 
@@ -65,12 +65,12 @@ module RocketApi
65
65
  # @return [String] text
66
66
  def plain_rubocop_yml_text(name)
67
67
  ["AllCops:",
68
- "\s\sExclude:",
69
- "\s\s\s\s- Gemfile",
70
- "\s\s\s\s- test/*",
71
- "\s\s\s\s- Rakefile",
72
- "\s\s\s\s- #{name}.gemspec",
73
- "\s\s\s\s- bin/*"].join("\n")
68
+ "#{TAB}Exclude:",
69
+ "#{DOUBLE_TAB}- Gemfile",
70
+ "#{DOUBLE_TAB}- test/*",
71
+ "#{DOUBLE_TAB}- Rakefile",
72
+ "#{DOUBLE_TAB}- #{name}.gemspec",
73
+ "#{DOUBLE_TAB}- bin/*"].join("\n")
74
74
  end
75
75
  end
76
76
  end
@@ -8,14 +8,24 @@ module RocketApi
8
8
  "task default: %i[test rubocop]\n",
9
9
  "require 'rake/testtask'",
10
10
  "Rake::TestTask.new do |test|",
11
- "\s\stest.libs << 'test'",
11
+ "#{TAB}test.libs << 'test'",
12
12
  "end\n",
13
13
  "require 'rubocop/rake_task'",
14
14
  "RuboCop::RakeTask.new do |task|",
15
- "\s\stask.fail_on_error = true",
16
- "\s\stask.requires << 'rubocop-rake'",
15
+ "#{TAB}task.fail_on_error = true",
16
+ "#{TAB}task.requires << 'rubocop-rake'",
17
17
  "end"].join("\n")
18
18
  end
19
+
20
+ def readme_text(project_name)
21
+ ["# #{project_name}",
22
+ "```sh",
23
+ "Add Product Version",
24
+ "```",
25
+ "```sh",
26
+ "Add description",
27
+ "```"].join("\n")
28
+ end
19
29
  end
20
30
  end
21
31
  end
@@ -5,25 +5,25 @@ module RocketApi
5
5
  module RackRepoPlainText
6
6
  def rack_routes_text
7
7
  ["module Constants",
8
- "\s\smodule Routes",
9
- "\s\s\s\sPING = \"/ping.json\".freeze",
10
- "\s\s\s\sMESSAGE_COUNT = \"/greeting.json\".freeze",
11
- "\s\send",
8
+ "#{TAB}module Routes",
9
+ "#{DOUBLE_TAB}PING = \"/ping.json\".freeze",
10
+ "#{DOUBLE_TAB}MESSAGE_COUNT = \"/greeting.json\".freeze",
11
+ "#{TAB}end",
12
12
  "end"].join("\n")
13
13
  end
14
14
 
15
15
  def rack_base_controller_text
16
16
  ["class BaseController",
17
- "\s\sdef initialize(request)",
18
- "\s\s\s\s@request = request",
19
- "\s\send\n",
20
- "\s\sdef ping",
21
- "\s\s\s\sbuild_response(\"pong\")",
22
- "\s\send\n",
23
- "\s\sprivate\n",
24
- "\s\sdef build_response(body, status: 200)",
25
- "\s\s\s\s[status, { \"Content-Type\" => \"text/json\" }, [body]]",
26
- "\s\send",
17
+ "#{TAB}def initialize(request)",
18
+ "#{DOUBLE_TAB}@request = request",
19
+ "#{TAB}end\n",
20
+ "#{TAB}def ping",
21
+ "#{DOUBLE_TAB}build_response(\"pong\")",
22
+ "#{TAB}end\n",
23
+ "#{TAB}private\n",
24
+ "#{TAB}def build_response(body, status: 200)",
25
+ "#{DOUBLE_TAB}[status, { \"Content-Type\" => \"text/json\" }, [body]]",
26
+ "#{TAB}end",
27
27
  "end"].join("\n")
28
28
  end
29
29
 
@@ -23,8 +23,7 @@ module RocketApi
23
23
  def self.init_dirs(**options)
24
24
  create_repo(options[:collection])
25
25
  rescue StandardError => e
26
- raise RocketApi::CreateDirError,
27
- "#{RocketApi::CREATE_FAILED} #{e.message}"
26
+ raise RocketApi::CreateDirError, "#{RocketApi::CREATE_FAILED} #{e.message}"
28
27
  end
29
28
 
30
29
  # @param [Hash] options
@@ -33,8 +32,7 @@ module RocketApi
33
32
  project_name = options[:project_name]
34
33
  options[:collection].each { |command| send(command, project_name) }
35
34
  rescue StandardError => e
36
- raise RocketApi::InitFilesError,
37
- "#{RocketApi::INIT_FAIL} #{e.message}"
35
+ raise RocketApi::InitFilesError, "#{RocketApi::INIT_FAIL} #{e.message}"
38
36
  end
39
37
  end
40
38
  end
@@ -0,0 +1,18 @@
1
+ module RocketApi
2
+ module Validation
3
+ # @parma [Array<String>] commands
4
+ # @raise [RocketApi::ValidationError] error
5
+ def validate_commands(*commands)
6
+ raise RocketApi::WRONG_RESPONSE if commands.any?(&:nil?)
7
+ rescue StandardError => e
8
+ raise RocketApi::ValidationError, e.message
9
+ end
10
+
11
+ # @raise [RocketApi::ValidationError] error
12
+ def available_to_init?
13
+ raise RocketApi::APP_DETECTED unless RocketApi::CHECK_APPS.map { |p| Dir.glob(p) }.flatten.empty?
14
+ rescue StandardError => e
15
+ raise RocketApi::ValidationError, e.message
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module RocketApi
2
- VERSION = "0.0.1.9".freeze
2
+ VERSION = "0.0.2.0".freeze
3
3
  end
data/lib/rocket_api.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require "rocket_api/rocket_commands"
2
2
  require "rocket_api/constants"
3
3
  require "rocket_api/errors"
4
+ require "rocket_api/validation"
5
+ require "rocket_api/lib"
4
6
  require "rocket_api/commands/files"
5
7
  require "rocket_api/commands/dirs"
6
8
  require "rocket_api/commands/rack_dir"
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.9
4
+ version: 0.0.2.0
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-27 00:00:00.000000000 Z
11
+ date: 2022-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -88,6 +88,7 @@ files:
88
88
  - Rakefile
89
89
  - bin/rocket_api
90
90
  - lib/rocket_api.rb
91
+ - lib/rocket_api/commands/bot_dirs.rb
91
92
  - lib/rocket_api/commands/dirs.rb
92
93
  - lib/rocket_api/commands/files.rb
93
94
  - lib/rocket_api/commands/gems_dir.rb
@@ -95,10 +96,12 @@ files:
95
96
  - lib/rocket_api/commands/rack_dir.rb
96
97
  - lib/rocket_api/constants.rb
97
98
  - lib/rocket_api/errors.rb
99
+ - lib/rocket_api/lib.rb
98
100
  - lib/rocket_api/library/gem_repo_plain_text.rb
99
101
  - lib/rocket_api/library/helper_plain_text.rb
100
102
  - lib/rocket_api/library/rack_repo_plain_text.rb
101
103
  - lib/rocket_api/rocket_commands.rb
104
+ - lib/rocket_api/validation.rb
102
105
  - lib/rocket_api/version.rb
103
106
  - rocket_api.gemspec
104
107
  - spec/rocket_api/rocket_commands_spec.rb