rocket_api 0.0.1.7 → 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: 37afe5384de38860240c2f361e0754b0f4c8a734be348f22979bab0d203ebf4a
4
- data.tar.gz: 721db37f2bcc3a254def12a42938127da04d490dc5ac933198dbb23e37d14ea9
3
+ metadata.gz: 97b2320edad5eb7b7b372adaa940695243cad6d763f015e0b808b97fa481c013
4
+ data.tar.gz: 1a8e5e39585f85c3936188bd1124409111d88b884daeb063224526edbb250b66
5
5
  SHA512:
6
- metadata.gz: 3aa07c310add8201f2016a2b10cd3ed5c41c95a402e86337446065d6f0a8cce5426ed88a92165a9814061dc3dab5b07bce9dd0f98c5efc926b7f702ac4bcaead
7
- data.tar.gz: a65a88c575bb6def0000fe27764ac5ecfe415c1d1f9d1d3313fb2a461d910888c9cdbc09a6c82479bf98e656ab064dec1ec1e95947080309eb72983916182b5c
6
+ metadata.gz: 34407638e02527001e3c0e454fe68cff4b2b63f634c81600c0acccc24967fdd619d6c5584ad274d485f0a4a7a951a5dc423583104a0fc5ff56fd9bf3cbe9d923
7
+ data.tar.gz: 0e420cbec9513e546e99a6bf53a44eb6b7c9fa8cb3c5c841d9b76d83faffd85df3b0b738feaeb0787ded74b17bd77e1c3c63e10db3af7c797a471c6fd8366b55
data/.rubocop.yml CHANGED
@@ -5,6 +5,7 @@ AllCops:
5
5
  - Rakefile
6
6
  - rocket_api.gemspec
7
7
  - bin/*
8
+ - spec/**/**
8
9
 
9
10
  Style/FrozenStringLiteralComment:
10
11
  Enabled: false
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
- # rocket_api
2
- Start creating gems with rocket_api
3
- - Add structure of gem repo by one commands
4
- - Init gems repo by files
1
+ # rocket api
2
+ Start creating new app with rocket_api:
3
+ - Add structure of gem repo
4
+ - Add structure of rack app
5
5
  ## Dependencies:
6
6
  ```sh
7
7
  ruby '2.7.2'
@@ -16,8 +16,12 @@ gem install rocket_api
16
16
  ```sh
17
17
  Availble commands:
18
18
  - init
19
- - gem [ project_name ]
19
+ -- gem [ project_name ]
20
+ -- rack [ project name ]
20
21
  In working directory:
21
-
22
22
  user@bulkas ~/gem/new_dir rocket_api [ init ] [ gem ] [ project_name ]
23
+ ```
24
+ ## Example
25
+ ```sh
26
+ user@bulkas ~/gem/new_dir rocket_api init new_gem
23
27
  ```
data/Rakefile CHANGED
@@ -2,12 +2,11 @@ require 'rubygems'
2
2
  require 'rake'
3
3
 
4
4
  desc "Run spec"
5
- task default: %i[test rubocop]
5
+ task default: %i[spec rubocop]
6
6
 
7
- require 'rake/testtask'
8
- Rake::TestTask.new do |test|
9
- test.libs << 'test'
10
- end
7
+ require "bundler/gem_tasks"
8
+ require "rspec/core/rake_task"
9
+ RSpec::Core::RakeTask.new(:spec)
11
10
 
12
11
  require 'rubocop/rake_task'
13
12
  RuboCop::RakeTask.new do |task|
data/bin/rocket_api CHANGED
@@ -2,27 +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
- 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
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)
15
+
16
+ if RocketApi::AVAILABLE_COMMANDS[base_command].keys.include?(sub_command)
17
+ RocketApi::AVAILABLE_COMMANDS[base_command][sub_command].each do |key, collection|
18
+ RocketApi::RocketCommands.send(key, collection: collection, project_name: project_name )
22
19
  end
23
20
  else
24
- puts RocketApi::WRONG_RESPONSE
21
+ raise RocketApi::WRONG_RESPONSE
25
22
  end
26
- else
27
- puts RocketApi::WRONG_RESPONSE
28
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
@@ -27,6 +27,11 @@ module RocketApi
27
27
  file_name = "test/test_version.rb"
28
28
  create_single_file(file_name, plain_gem_test_version_text(name, class_name_camel(name)))
29
29
  end
30
+
31
+ def rubocop_yml!(name)
32
+ file_name = ".rubocop.yml"
33
+ create_single_file(file_name, plain_rubocop_yml_text(name))
34
+ end
30
35
  end
31
36
  end
32
37
  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)
@@ -0,0 +1,60 @@
1
+ module RocketApi
2
+ module Commands
3
+ module RackDir
4
+ def rack_routes!(_name)
5
+ dir_name = "app/constants"
6
+ create_dir(dir_name)
7
+ file_name = "#{dir_name}/routes.rb"
8
+ create_single_file(file_name, rack_routes_text)
9
+ end
10
+
11
+ def rack_base_controller!(_name)
12
+ dir_name = "app/controllers"
13
+ create_dir(dir_name)
14
+ file_name = "#{dir_name}/base_controller.rb"
15
+ create_single_file(file_name, rack_base_controller_text)
16
+ end
17
+
18
+ def rack_config_ru!(_name)
19
+ file_name = "config.ru"
20
+ create_single_file(file_name, rack_config_ru)
21
+ end
22
+
23
+ def rack_app!(_name)
24
+ dir_name = "config/app"
25
+
26
+ create_dir(dir_name) unless is_exist?(dir_name)
27
+
28
+ file_name = "#{dir_name}/app.rb"
29
+ create_single_file(file_name, rack_app_text)
30
+ end
31
+
32
+ def rack_router!(_name)
33
+ dir_name = "config/app"
34
+
35
+ create_dir(dir_name) unless is_exist?(dir_name)
36
+
37
+ file_name = "#{dir_name}/router.rb"
38
+ create_single_file(file_name, rack_router_text)
39
+ end
40
+
41
+ def rack_initializers!(_name)
42
+ dir_name = "config/initializers"
43
+
44
+ create_dir(dir_name) unless is_exist?(dir_name)
45
+
46
+ file_name = "#{dir_name}/001_settings.rb"
47
+ create_single_file(file_name, rack_initializers_text)
48
+ end
49
+
50
+ def rack_application!(_name)
51
+ file_name = "config/application.rb"
52
+ create_single_file(file_name, rack_application_text)
53
+ end
54
+
55
+ def rack_gemfile!(_name)
56
+ create_single_file("Gemfile", rack_gemfile_text)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,13 +1,32 @@
1
1
  module RocketApi
2
2
  # Valid input
3
3
  REGEXP_VALID = /[^0-9A-Za-z_-]/.freeze
4
+ CHECK_APPS = %w[*.gemspec *.ru].freeze
5
+
6
+ # Valid commands
7
+ COMMANDS = { init: "init", gem: "gem", rack: "rack", bot: "bot" }.freeze
8
+
9
+ # Gem
10
+ GEM_DIRS = %w[bin lib test].freeze
11
+ GEM_FILES = %w[bin! gemspec! gems_main_file! gems_version! gem_test! rake_file! gitignore! gem_file! rubocop_yml!].freeze
12
+ GEM_MAP = { init_dirs: GEM_DIRS, init_files: GEM_FILES }.freeze
13
+
14
+ # Rack
15
+ RACK_DIRS = %w[app config test].freeze
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
+ RACK_MAP = { init_dirs: RACK_DIRS, init_files: RACK_FILES }.freeze
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
4
23
 
5
24
  # Dirs map
6
- GEM_PROJECTS_DIR = %w[bin lib test].freeze
7
- GEM_COMMANDS = %w[bin! gemspec! gems_main_file! gems_version! gem_test! rake_file! gitignore! gem_file!].freeze
8
25
  AVAILABLE_COMMANDS = {
9
- init: {
10
- gem: %w[init_gem_dir init_gem_files]
26
+ COMMANDS[:init] => {
27
+ COMMANDS[:gem] => GEM_MAP,
28
+ COMMANDS[:rack] => RACK_MAP,
29
+ COMMANDS[:bot] => BOT_MAP
11
30
  }
12
31
  }.freeze
13
32
 
@@ -16,12 +35,16 @@ module RocketApi
16
35
 
17
36
  # Answers
18
37
  INIT_DIR_ERROR = "Init directory error".freeze
19
- GEM_DETECTED = "another one gem exist".freeze
38
+ APP_DETECTED = "Another one app exist".freeze
20
39
  FOLDER_EXIST = "folder exist:".freeze
21
40
  FILE_EXIST = "file already exist:".freeze
22
41
  WRONG_RESPONSE = "Wrong command".freeze
23
42
  EMPTY_NAME = "Project name is empty".freeze
24
43
  INIT_FAIL = "Init action fail:".freeze
25
- CREATE_FAILED = "Create failed:".freeze
26
- CREATE_SUCCESS = "Successfully created:".freeze
44
+ CREATE_FAILED = "Fail:".freeze
45
+ CREATE_SUCCESS = "Success:".freeze
46
+
47
+ # Text
48
+ TAB = "\s\s".freeze
49
+ DOUBLE_TAB = "\s\s\s\s".freeze
27
50
  end
@@ -1,8 +1,13 @@
1
1
  module RocketApi
2
2
  # Base error
3
3
  class Error < StandardError; end
4
+
4
5
  # Raise in case of dir creation error
5
6
  class CreateDirError < Error; end
7
+
6
8
  # Raise in case of file creation error
7
9
  class InitFilesError < Error; end
10
+
11
+ # Raise in case of validation error
12
+ class ValidationError < Error; end
8
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
@@ -5,52 +5,73 @@ module RocketApi
5
5
  ".idea/\nGemfile.lock\n*.gem".freeze
6
6
  end
7
7
 
8
+ # @param [String] module_name
9
+ # @return [String] text
8
10
  def plain_version_text(module_name)
9
11
  "module #{module_name}\n\tVERSION = \"0.0.1\".freeze\nend"
10
12
  end
11
13
 
14
+ # @param [String] name
15
+ # @param [String] module_name
16
+ # @return [String] text
12
17
  def plain_gemspec_text(name, module_name)
13
18
  ["lib = File.expand_path(\"lib\", __dir__)",
14
19
  "$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)\n",
15
20
  "require 'English'",
16
21
  "require '#{name}/version'\n",
17
22
  "Gem::Specification.new do |s|",
18
- "\ts.specification_version = 2 if s.respond_to? :specification_version=",
19
- "\tif s.respond_to? :required_rubygems_version=",
20
- "\t\ts.required_rubygems_version = Gem::Requirement.new('>= 0')",
21
- "\tend",
22
- "\ts.rubygems_version = 'RUBY_VERSION'",
23
- "\ts.required_ruby_version = 'RUBY_VERSION'",
24
- "\ts.name = '#{name}'",
25
- "\ts.version = #{module_name}::VERSION",
26
- "\ts.executables << '#{name}'",
27
- "\ts.summary = 'PUT_SUMMARY'",
28
- "\ts.description = 'PUT_DESCRIPTION'",
29
- "\ts.authors = ['AUTHOR']",
30
- "\ts.email = 'AUTHOR_MAIL'",
31
- "\ts.homepage = 'https://github.com/...'",
32
- "\ts.files = `git ls-files`.split($RS)",
33
- "\ts.add_dependency \"rubocop\"",
34
- "\ts.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\"",
35
40
  "end"].join("\n")
36
41
  end
37
42
 
43
+ # @param [String] name
44
+ # @param [String] module_name
45
+ # @return [String] text
38
46
  def plain_gem_test_version_text(name, module_name)
39
47
  ["require 'minitest/autorun'",
40
48
  "require '#{name}/version'\n",
41
49
  "class TestVersion < Minitest::Test",
42
- "\tinclude #{module_name}\n",
43
- "\tdef test_ping",
44
- "\t\tassert_equal(\"0.0.1\", #{module_name}::VERSION)",
45
- "\tend",
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",
46
54
  "end"].join("\n")
47
55
  end
48
56
 
57
+ # @return [String] text
49
58
  def gemfile_text
50
59
  ["source 'https://rubygems.org/'",
51
60
  "ruby 'RUBY_VERSION'",
52
61
  "gemspec"].join("\n")
53
62
  end
63
+
64
+ # @param [String] name
65
+ # @return [String] text
66
+ def plain_rubocop_yml_text(name)
67
+ ["AllCops:",
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
+ end
54
75
  end
55
76
  end
56
77
  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
- "\ttest.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
- "\ttask.fail_on_error = true",
16
- "\ttask.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
@@ -0,0 +1,113 @@
1
+ require "rocket_api/constants"
2
+
3
+ module RocketApi
4
+ module Library
5
+ module RackRepoPlainText
6
+ def rack_routes_text
7
+ ["module Constants",
8
+ "#{TAB}module Routes",
9
+ "#{DOUBLE_TAB}PING = \"/ping.json\".freeze",
10
+ "#{DOUBLE_TAB}MESSAGE_COUNT = \"/greeting.json\".freeze",
11
+ "#{TAB}end",
12
+ "end"].join("\n")
13
+ end
14
+
15
+ def rack_base_controller_text
16
+ ["class BaseController",
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
+ "end"].join("\n")
28
+ end
29
+
30
+ def rack_config_ru
31
+ ["require_relative \"config/application\"",
32
+ "require_all \"./config/app\"\n",
33
+ "secret_key = SecureRandom.hex(32)",
34
+ "use Rack::Session::Cookie, secret: secret_key, same_site: true, max_age: 86400\n",
35
+ "run Rack::URLMap.new('/' => Rack::Builder.new { run App.new })"].join("\n")
36
+ end
37
+
38
+ def rack_app_text
39
+ ["class App",
40
+ "#{TAB}def call(env)",
41
+ "#{DOUBLE_TAB}request = Rack::Request.new(env)",
42
+ "#{DOUBLE_TAB}serve_request(request)",
43
+ "#{TAB}end\n",
44
+ "#{TAB}def serve_request(request)",
45
+ "#{DOUBLE_TAB}Router.new(request).route!",
46
+ "#{TAB}end",
47
+ "end"].join("\n")
48
+ end
49
+
50
+ def rack_router_text
51
+ ["class Router",
52
+ "#{TAB}def initialize(request)",
53
+ "#{DOUBLE_TAB}@request = request",
54
+ "#{TAB}end\n",
55
+ "#{TAB}def route!",
56
+ "#{DOUBLE_TAB}return controller.not_found unless @request.post?\n",
57
+ "#{DOUBLE_TAB}case @request.path",
58
+ "#{DOUBLE_TAB}when Constants::Routes::PING",
59
+ "#{DOUBLE_TAB}#{TAB}controller.ping",
60
+ "#{DOUBLE_TAB}else",
61
+ "#{DOUBLE_TAB}#{TAB}controller.not_found",
62
+ "#{DOUBLE_TAB}end",
63
+ "#{TAB}end\n",
64
+ "#{TAB}private\n",
65
+ "#{TAB}def controller",
66
+ "#{DOUBLE_TAB}@controller ||= BaseController.new(@request)",
67
+ "#{TAB}end\n",
68
+ "#{TAB}def params",
69
+ "#{DOUBLE_TAB}JSON.parse(@request.body.read)",
70
+ "#{TAB}end",
71
+ "end"].join("\n")
72
+ end
73
+
74
+ def rack_initializers_text
75
+ ["# frozen_string_literal: true\n",
76
+ "require \"config\"\n",
77
+ "Config.setup do |config|",
78
+ "#{TAB}config.const_name = \"Settings\"",
79
+ "#{TAB}config.use_env = false",
80
+ "end\n",
81
+ "env = ::ActiveSupport::StringInquirer.new(ENV[\"RACK_ENV\"] || \"development\")",
82
+ "path = Dir.pwd << (\"/config\")",
83
+ "Config.load_and_set_settings(Config.setting_files(path, env))\n",
84
+ "Settings.env = env"].join("\n")
85
+ end
86
+
87
+ def rack_application_text
88
+ ["# frozen_string_literal: true\n",
89
+ "# require gems",
90
+ "require \"bundler\"",
91
+ "Bundler.require(:default, ENV[\"RACK_ENV\"] || \"development\")\n",
92
+ "require \"simplecov\" if ENV[\"COVERAGE\"]\n",
93
+ "# require additional gem files",
94
+ "require \"active_support/all\"\n",
95
+ "# initialize application, logger, gems, etc.",
96
+ "require_all \"config/initializers\"\n",
97
+ "# require application\n",
98
+ "require_all \"app\""].join("\n")
99
+ end
100
+
101
+ def rack_gemfile_text
102
+ ["source 'https://rubygems.org/'",
103
+ "ruby 'RUBY_VERSION'\n",
104
+ "gem 'rack', 'VERSION'",
105
+ "gem 'rack-parser'",
106
+ "gem 'rake', 'VERSION'",
107
+ "gem 'require_all', '~> VERSION'",
108
+ "gem 'activesupport', '~> VERSION'",
109
+ "gem 'config', '~> VERSION'"].join("\n")
110
+ end
111
+ end
112
+ end
113
+ end
@@ -2,41 +2,37 @@ require "rocket_api/commands/files"
2
2
  require "rocket_api/commands/dirs"
3
3
  require "rocket_api/commands/gems_dir"
4
4
  require "rocket_api/commands/helper"
5
+ require "rocket_api/commands/rack_dir"
5
6
  require "rocket_api/library/gem_repo_plain_text"
7
+ require "rocket_api/library/rack_repo_plain_text"
6
8
  require "rocket_api/library/helper_plain_text"
7
9
 
8
10
  module RocketApi
9
11
  class RocketCommands
10
12
  extend RocketApi::Commands::Files
11
13
  extend RocketApi::Commands::Dirs
12
- extend RocketApi::Commands::GemsDir
13
14
  extend RocketApi::Commands::Helper
14
- extend RocketApi::Library::GemRepoPlainText
15
+ extend RocketApi::Commands::GemsDir
16
+ extend RocketApi::Commands::RackDir
15
17
  extend RocketApi::Library::HelperPlainText
18
+ extend RocketApi::Library::GemRepoPlainText
19
+ extend RocketApi::Library::RackRepoPlainText
16
20
 
17
21
  # @param [Hah] options
18
- # ...
19
22
  # @raise [RocketApi::CreateDirError]
20
- def self.init_gem_dir(**_options)
21
- raise GEM_DETECTED unless Dir.glob("*.gemspec").empty?
22
-
23
- create_repo(RocketApi::GEM_PROJECTS_DIR)
23
+ def self.init_dirs(**options)
24
+ create_repo(options[:collection])
24
25
  rescue StandardError => e
25
- raise RocketApi::CreateDirError,
26
- "#{RocketApi::CREATE_FAILED} #{e.message}"
26
+ raise RocketApi::CreateDirError, "#{RocketApi::CREATE_FAILED} #{e.message}"
27
27
  end
28
28
 
29
29
  # @param [Hash] options
30
- # ...
31
30
  # @raise [RocketApi::InitFilesError] error
32
- def self.init_gem_files(**options)
33
- raise RocketApi::EMPTY_NAME if options[:project_name].nil?
34
-
31
+ def self.init_files(**options)
35
32
  project_name = options[:project_name]
36
- RocketApi::GEM_COMMANDS.each { |command| send(command, project_name) }
33
+ options[:collection].each { |command| send(command, project_name) }
37
34
  rescue StandardError => e
38
- raise RocketApi::InitFilesError,
39
- "#{RocketApi::INIT_FAIL} #{e.message}"
35
+ raise RocketApi::InitFilesError, "#{RocketApi::INIT_FAIL} #{e.message}"
40
36
  end
41
37
  end
42
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.7".freeze
2
+ VERSION = "0.0.2.0".freeze
3
3
  end
data/lib/rocket_api.rb CHANGED
@@ -1,8 +1,12 @@
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"
8
+ require "rocket_api/commands/rack_dir"
6
9
  require "rocket_api/commands/gems_dir"
7
10
  require "rocket_api/commands/helper"
8
11
  require "rocket_api/library/gem_repo_plain_text"
12
+ require "rocket_api/library/rack_repo_plain_text"
data/rocket_api.gemspec CHANGED
@@ -21,6 +21,8 @@ Gem::Specification.new do |s|
21
21
  s.email = "ilyafulleveline@gmail.com"
22
22
  s.homepage = "https://github.com/ikondratev/rocket_api"
23
23
  s.files = `git ls-files`.split($RS)
24
+ s.add_dependency "bundler", "~> 2"
24
25
  s.add_dependency "rubocop", "~> 1.26"
25
26
  s.add_dependency "rubocop-rake"
27
+ s.add_dependency "rspec", "~> 3.0"
26
28
  end
@@ -0,0 +1,21 @@
1
+ require "rocket_api/rocket_commands"
2
+ require "rocket_api/errors"
3
+ require "rocket_api/constants"
4
+
5
+ RSpec.describe RocketApi::RocketCommands do
6
+ context "#init_gem_files" do
7
+ context "in case of empty file name" do
8
+ it "should raise RocketApi::InitFilesError" do
9
+ expect{ RocketApi::RocketCommands.init_files({}) }.to raise_error(RocketApi::InitFilesError)
10
+ end
11
+ end
12
+ end
13
+
14
+ context "#init_gem_dir" do
15
+ context "in case of not empty dir" do
16
+ it "should raise RocketApi::CreateDirError" do
17
+ expect{ RocketApi::RocketCommands.init_dirs({}) }.to raise_error(RocketApi::CreateDirError)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ require "rocket_api/version"
2
+
3
+ RSpec.describe RocketApi do
4
+ it "has a valid version number" do
5
+ expect(Gem::Version.new(RocketApi::VERSION).class).to eq(Gem::Version)
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ require "bundler/setup"
2
+ require "rocket_api"
3
+
4
+ RSpec.configure do |config|
5
+ config.example_status_persistance_file_path = ".rspec_status"
6
+ config.disable_monkey_patching!
7
+ config.expect_with :rspec do |c|
8
+ c.syntax = :expect
9
+ end
10
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rocket_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.7
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-20 00:00:00.000000000 Z
11
+ date: 2022-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rubocop
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,6 +52,20 @@ dependencies:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
41
69
  description: |-
42
70
  Initialize directory with gem's structure.
43
71
  Include:
@@ -60,18 +88,25 @@ files:
60
88
  - Rakefile
61
89
  - bin/rocket_api
62
90
  - lib/rocket_api.rb
91
+ - lib/rocket_api/commands/bot_dirs.rb
63
92
  - lib/rocket_api/commands/dirs.rb
64
93
  - lib/rocket_api/commands/files.rb
65
94
  - lib/rocket_api/commands/gems_dir.rb
66
95
  - lib/rocket_api/commands/helper.rb
96
+ - lib/rocket_api/commands/rack_dir.rb
67
97
  - lib/rocket_api/constants.rb
68
98
  - lib/rocket_api/errors.rb
99
+ - lib/rocket_api/lib.rb
69
100
  - lib/rocket_api/library/gem_repo_plain_text.rb
70
101
  - lib/rocket_api/library/helper_plain_text.rb
102
+ - lib/rocket_api/library/rack_repo_plain_text.rb
71
103
  - lib/rocket_api/rocket_commands.rb
104
+ - lib/rocket_api/validation.rb
72
105
  - lib/rocket_api/version.rb
73
106
  - rocket_api.gemspec
74
- - test/test_version.rb
107
+ - spec/rocket_api/rocket_commands_spec.rb
108
+ - spec/rocket_api_spec.rb
109
+ - spec/spec_helper.rb
75
110
  homepage: https://github.com/ikondratev/rocket_api
76
111
  licenses:
77
112
  - MIT
data/test/test_version.rb DELETED
@@ -1,9 +0,0 @@
1
- require 'minitest/autorun'
2
- require 'rocket_api/version'
3
-
4
- class TestVersion < Minitest::Test
5
- include RocketApi
6
- def test_ping
7
- assert_equal("0.0.1.7", RocketApi::VERSION)
8
- end
9
- end