ruby-api 1.0.2 → 1.0.3
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 +4 -4
- data/lib/ruby_api.rb +24 -4
- data/lib/ruby_api/application.rb +11 -15
- data/lib/ruby_api/cli/generate.rb +17 -0
- data/lib/ruby_api/cli/main.rb +8 -4
- data/lib/ruby_api/cli/server.rb +19 -0
- data/lib/ruby_api/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 690eb8fb0de772562ea754e3baf9d694f1180df1
|
4
|
+
data.tar.gz: 93a607e48c16654b6cb1b9f44836ac8ebfc7ac16
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2d2518098e9d1c9010d0986cf55c68a05219a5172f1ef4593dc1745dbd2823c98875037d4451912f033f399f0bba72c0a7450d0d12d3122889149772f996d1b
|
7
|
+
data.tar.gz: 93fd8c681642c55f06634dfa35037bb68b625542294ef4a9848c1ed1d98217c696bda8721a84157b80ff734bfd25de55585b495cb160f5ac620bc97e49c6caa3
|
data/lib/ruby_api.rb
CHANGED
@@ -18,12 +18,32 @@ module RubyAPI
|
|
18
18
|
require_relative 'ruby_api/application'
|
19
19
|
|
20
20
|
CONFIG_DIR = 'config'
|
21
|
+
CONFIG_FILE = 'app.yml'
|
21
22
|
BOOT_SCRIPT = 'boot'
|
22
23
|
|
23
|
-
def self.application(
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
def self.application(root, overrides = {})
|
25
|
+
@root = root
|
26
|
+
Application.new(config(overrides)).boot
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.config(overrides = {})
|
30
|
+
path = overrides[:config_file]
|
31
|
+
path ||= File.join CONFIG_DIR, CONFIG_FILE
|
32
|
+
path = path(path)
|
33
|
+
raise "Config missing at #{path}" unless File.exist?(path)
|
34
|
+
Config.new YAML.load_file(path)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.root=(path)
|
38
|
+
@root = path
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.root
|
42
|
+
@root
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.path(path)
|
46
|
+
File.join @root, path
|
27
47
|
end
|
28
48
|
|
29
49
|
def self.environment
|
data/lib/ruby_api/application.rb
CHANGED
@@ -4,35 +4,30 @@ module RubyAPI
|
|
4
4
|
# Application
|
5
5
|
class Application
|
6
6
|
APP_MODULE_NAME = 'APP'
|
7
|
-
APP_SOURCE_PATH = '
|
7
|
+
APP_SOURCE_PATH = 'src/main'
|
8
8
|
|
9
9
|
attr_reader :config, :logger, :routes
|
10
10
|
|
11
|
-
def initialize(
|
12
|
-
|
11
|
+
def initialize(config)
|
12
|
+
raise "Invalid config: #{config.inspect}" unless config.is_a?(Config)
|
13
|
+
@config = config
|
13
14
|
@routes = load_routes
|
14
15
|
end
|
15
16
|
|
16
|
-
def load_config(cfg)
|
17
|
-
require_hash_or_string(cfg, 'Invalid configuration: %s')
|
18
|
-
cfg = YAML.load_file cfg if cfg.is_a?(String)
|
19
|
-
Config.new(cfg)
|
20
|
-
end
|
21
|
-
|
22
17
|
def load_routes
|
23
18
|
return {} unless config.key?(:routes)
|
24
19
|
|
25
20
|
routes = config.routes
|
26
21
|
require_hash_or_string(routes, 'Invalid routes config: %s')
|
27
|
-
routes = YAML.load_file routes if routes.is_a?(String)
|
22
|
+
routes = YAML.load_file RubyAPI.path(routes) if routes.is_a?(String)
|
28
23
|
@routes = routes.deep_symbolize_keys!
|
29
24
|
end
|
30
25
|
|
31
26
|
def boot
|
32
27
|
@logger = Logger.new log_path[:info]
|
33
28
|
@logger_err = Logger.new log_path[:error]
|
34
|
-
require boot_script if boot_script?
|
35
|
-
require app_path
|
29
|
+
require RubyAPI.path(boot_script) if boot_script?
|
30
|
+
require RubyAPI.path(app_path)
|
36
31
|
self
|
37
32
|
end
|
38
33
|
|
@@ -76,9 +71,10 @@ module RubyAPI
|
|
76
71
|
|
77
72
|
def boot_script?
|
78
73
|
return false unless config.key?(:boot_script)
|
79
|
-
path =
|
80
|
-
|
81
|
-
path
|
74
|
+
path = RubyAPI.path(boot_script)
|
75
|
+
return true if File.exist?(path)
|
76
|
+
logger.warn "Boot script not found at: #{path}"
|
77
|
+
false
|
82
78
|
end
|
83
79
|
|
84
80
|
def process(request)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../../ruby_api'
|
4
|
+
|
5
|
+
module RubyAPI
|
6
|
+
module Cli
|
7
|
+
# :nodoc
|
8
|
+
class Generate < Thor
|
9
|
+
desc 'feature NAME', 'generate application feature module'
|
10
|
+
def feature(name)
|
11
|
+
path = File.join RubyAPI::CONFIG_DIR, RubyAPI::CONFIG_FILE
|
12
|
+
config = RubyAPI.config
|
13
|
+
puts config.to_yaml
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/ruby_api/cli/main.rb
CHANGED
@@ -1,13 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require_relative 'server'
|
4
|
+
require_relative 'generate'
|
5
|
+
|
3
6
|
module RubyAPI
|
4
7
|
module Cli
|
5
8
|
# RubyAPI Main CLI command
|
6
9
|
class Main < Thor
|
7
|
-
desc '
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
desc 'server COMMAND', 'control API server'
|
11
|
+
subcommand 'server', Server
|
12
|
+
|
13
|
+
desc 'generate OBJECT [OPTIONS]', 'generate framework objects'
|
14
|
+
subcommand 'generate', Generate
|
11
15
|
end
|
12
16
|
end
|
13
17
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyAPI
|
4
|
+
module Cli
|
5
|
+
# :nodoc
|
6
|
+
class Server < Thor
|
7
|
+
desc 'start', 'start API server'
|
8
|
+
option :server, aliases: [:s], type: :string, default: 'puma'
|
9
|
+
option :port, aliases: [:p], type: :numeric, default: 1234
|
10
|
+
option :config, aliases: [:c], type: :string, default: 'config.ru'
|
11
|
+
def start
|
12
|
+
exec format('bundle exec %<server>s -p %<port>d %<config>s',
|
13
|
+
server: options[:server],
|
14
|
+
port: options[:port],
|
15
|
+
config: options[:config])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/ruby_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Voislav Jovanovic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -119,7 +119,9 @@ files:
|
|
119
119
|
- lib/ruby_api.rb
|
120
120
|
- lib/ruby_api/application.rb
|
121
121
|
- lib/ruby_api/cli.rb
|
122
|
+
- lib/ruby_api/cli/generate.rb
|
122
123
|
- lib/ruby_api/cli/main.rb
|
124
|
+
- lib/ruby_api/cli/server.rb
|
123
125
|
- lib/ruby_api/config.rb
|
124
126
|
- lib/ruby_api/operation.rb
|
125
127
|
- lib/ruby_api/request.rb
|