Module: RocketApi::Library::RackRepoPlainText

Included in:
RocketCommands
Defined in:
lib/rocket_api/library/rack_repo_plain_text.rb

Instance Method Summary collapse

Instance Method Details

#rack_app_textObject



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rocket_api/library/rack_repo_plain_text.rb', line 38

def rack_app_text
  ["class App",
   "#{TAB}def call(env)",
   "#{DOUBLE_TAB}request = Rack::Request.new(env)",
   "#{DOUBLE_TAB}serve_request(request)",
   "#{TAB}end\n",
   "#{TAB}def serve_request(request)",
   "#{DOUBLE_TAB}Router.new(request).route!",
   "#{TAB}end",
   "end"].join("\n")
end

#rack_application_textObject



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/rocket_api/library/rack_repo_plain_text.rb', line 87

def rack_application_text
  ["# frozen_string_literal: true\n",
   "# require gems",
   "require \"bundler\"",
   "Bundler.require(:default, ENV[\"RACK_ENV\"] || \"development\")\n",
   "require \"simplecov\" if ENV[\"COVERAGE\"]\n",
   "# require additional gem files",
   "require \"active_support/all\"\n",
   "# initialize application, logger, gems, etc.",
   "require_all \"config/initializers\"\n",
   "# require application\n",
   "require_all \"app\""].join("\n")
end

#rack_base_controller_textObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rocket_api/library/rack_repo_plain_text.rb', line 15

def rack_base_controller_text
  ["class BaseController",
   "#{TAB}def initialize(request)",
   "#{DOUBLE_TAB}@request = request",
   "#{TAB}end\n",
   "#{TAB}def ping",
   "#{DOUBLE_TAB}build_response(\"pong\")",
   "#{TAB}end\n",
   "#{TAB}private\n",
   "#{TAB}def build_response(body, status: 200)",
   "#{DOUBLE_TAB}[status, { \"Content-Type\" => \"text/json\" }, [body]]",
   "#{TAB}end",
   "end"].join("\n")
end

#rack_config_ruObject



30
31
32
33
34
35
36
# File 'lib/rocket_api/library/rack_repo_plain_text.rb', line 30

def rack_config_ru
  ["require_relative \"config/application\"",
   "require_all \"./config/app\"\n",
   "secret_key = SecureRandom.hex(32)",
   "use Rack::Session::Cookie, secret: secret_key, same_site: true, max_age: 86400\n",
   "run Rack::URLMap.new('/' => Rack::Builder.new { run App.new })"].join("\n")
end

#rack_gemfile_textObject



101
102
103
104
105
106
107
108
109
110
# File 'lib/rocket_api/library/rack_repo_plain_text.rb', line 101

def rack_gemfile_text
  ["source 'https://rubygems.org/'",
   "ruby 'RUBY_VERSION'\n",
   "gem 'rack', 'VERSION'",
   "gem 'rack-parser'",
   "gem 'rake', 'VERSION'",
   "gem 'require_all', '~> VERSION'",
   "gem 'activesupport', '~> VERSION'",
   "gem 'config', '~> VERSION'"].join("\n")
end

#rack_initializers_textObject



74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/rocket_api/library/rack_repo_plain_text.rb', line 74

def rack_initializers_text
  ["# frozen_string_literal: true\n",
   "require \"config\"\n",
   "Config.setup do |config|",
   "#{TAB}config.const_name = \"Settings\"",
   "#{TAB}config.use_env = false",
   "end\n",
   "env = ::ActiveSupport::StringInquirer.new(ENV[\"RACK_ENV\"] || \"development\")",
   "path = Dir.pwd << (\"/config\")",
   "Config.load_and_set_settings(Config.setting_files(path, env))\n",
   "Settings.env = env"].join("\n")
end

#rack_router_textObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/rocket_api/library/rack_repo_plain_text.rb', line 50

def rack_router_text
  ["class Router",
   "#{TAB}def initialize(request)",
   "#{DOUBLE_TAB}@request = request",
   "#{TAB}end\n",
   "#{TAB}def route!",
   "#{DOUBLE_TAB}return controller.not_found unless @request.post?\n",
   "#{DOUBLE_TAB}case @request.path",
   "#{DOUBLE_TAB}when Constants::Routes::PING",
   "#{DOUBLE_TAB}#{TAB}controller.ping",
   "#{DOUBLE_TAB}else",
   "#{DOUBLE_TAB}#{TAB}controller.not_found",
   "#{DOUBLE_TAB}end",
   "#{TAB}end\n",
   "#{TAB}private\n",
   "#{TAB}def controller",
   "#{DOUBLE_TAB}@controller ||= BaseController.new(@request)",
   "#{TAB}end\n",
   "#{TAB}def params",
   "#{DOUBLE_TAB}JSON.parse(@request.body.read)",
   "#{TAB}end",
   "end"].join("\n")
end

#rack_routes_textObject



6
7
8
9
10
11
12
13
# File 'lib/rocket_api/library/rack_repo_plain_text.rb', line 6

def rack_routes_text
  ["module Constants",
   "#{TAB}module Routes",
   "#{DOUBLE_TAB}PING = \"/ping.json\".freeze",
   "#{DOUBLE_TAB}MESSAGE_COUNT = \"/greeting.json\".freeze",
   "#{TAB}end",
   "end"].join("\n")
end