schemaless_rest_api 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 49fba7a856b268a6077d6597c20687d0d056cce2049fb5c0590da046acebf91f
4
- data.tar.gz: 2ac45839af0b7d4e273812bcf6a4a9d3f750d958285c3f9fcfccf143ee4d8c57
3
+ metadata.gz: 6f42e7bccaab28e6dc750c4351e18500689d1fb13a72bda6d0f1417cc5cef630
4
+ data.tar.gz: d47a29830a56c986c04bdc92c0c07758efcbe197de71a0183552af628ee66dc0
5
5
  SHA512:
6
- metadata.gz: 5c545f176d807dff6894b10a54aba45737968157247261b1a973ae471ec60155834a8847a43edb3c2ee50ad2a2b562846f5513479112402f3013b7da6a84a0c2
7
- data.tar.gz: 35f4ed2bc211ac4bf163296b69c29362a7d13a3c705898e7a5a07438d3c8b071907acfd0792fb9b84e81519e74b6cfd95276156948ae422d27886a13ebb7421c
6
+ metadata.gz: 366cd2cf898fc3cca3ba5b90d29d44fa08e43b5a0a8154eec309c21d9a7012a8c2498912818f2251e664bf2568bfdbcead72ac59e6d837f6a844fd43b64b2a07
7
+ data.tar.gz: 65cfacda5630298c9e50165b3a2a5420ecf6965347f32f92226afcb6137716207732377714d9b59d7bdda228e5aacc6f23adb39a97ea0be062bc269804b61568
@@ -1,9 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # typed: true
4
+
3
5
  # Entities mapped by environment variables
4
6
  class Entities
5
7
  @models = {}
6
8
  class << self
9
+ # @return [Hash] Hash of models
7
10
  attr_accessor :models
8
11
  end
9
12
  end
@@ -2,6 +2,7 @@ require "mongo"
2
2
 
3
3
  # typed: false - MongoClient new
4
4
 
5
+ # Client to talk to Mongo database
5
6
  module MongoClient
6
7
  class << self
7
8
  # @return Client to work with MongoDb
@@ -3,6 +3,8 @@
3
3
  require "sinatra"
4
4
  require "puma"
5
5
  require "route_downcaser"
6
+ require "prometheus/middleware/collector"
7
+ require "prometheus/middleware/exporter"
6
8
  require_relative "server_utils"
7
9
 
8
10
  # Server with endpoints generated based on Entities with CRUD operations for them
@@ -11,6 +13,8 @@ class RestServer < Sinatra::Base
11
13
  enable :logging if ENV["debug"] == "true"
12
14
  set :bind, "0.0.0.0"
13
15
  use RouteDowncaser::DowncaseRouteMiddleware
16
+ use Prometheus::Middleware::Collector
17
+ use Prometheus::Middleware::Exporter
14
18
  helpers ServerUtils
15
19
 
16
20
  before do
@@ -60,7 +64,7 @@ class RestServer < Sinatra::Base
60
64
 
61
65
  get "/" do
62
66
  summary = { models: Entities.models.keys.to_s,
63
- docs_url: "<a href=/swagger>Swagger docs</a>" }
67
+ docs_url: "<a href='#{ENV["base_path"]}/swagger'>Swagger docs</a>" }
64
68
  summary[:db] = MongoClient.client.summary.to_s if ENV["mongodb"]
65
69
  JSON.generate(summary)
66
70
  rescue StandardError => e
@@ -13,7 +13,7 @@ class SwaggerBuilder
13
13
  doc["info"] = build_info(models)
14
14
  doc["host"] = host_with_port
15
15
  doc["schemes"] = "http"
16
- doc["basePath"] = "/"
16
+ doc["basePath"] = "/#{ENV["base_path"]}"
17
17
  doc["paths"] = generate_paths_for models
18
18
  JSON.generate(doc)
19
19
  end
@@ -57,7 +57,7 @@ class SwaggerBuilder
57
57
  }
58
58
  },
59
59
  get: {
60
- parameters: [
60
+ parameters: [
61
61
  {
62
62
  name: "params",
63
63
  description: "Any key can be used to filter #{model} by",
@@ -94,7 +94,7 @@ class SwaggerBuilder
94
94
  end
95
95
 
96
96
  def paths_at_id(model)
97
- {
97
+ {
98
98
  get: {
99
99
  description: "Data of #{model} at passed id",
100
100
  parameters: id_params(model),
@@ -3,5 +3,5 @@
3
3
  # typed: true
4
4
 
5
5
  module SchemalessRestApi
6
- VERSION = "0.5.1"
6
+ VERSION = "0.6.0"
7
7
  end
@@ -12,6 +12,7 @@ require "json"
12
12
  require "securerandom"
13
13
 
14
14
  ENV["APP_ENV"] ||= "production"
15
+ ENV["base_path"] ||= ""
15
16
 
16
17
  # Global params for Schemalass REST API
17
18
  module SchemalessRestApi
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schemaless_rest_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Garratt
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-19 00:00:00.000000000 Z
11
+ date: 2024-06-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongo
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: prometheus-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: puma
43
57
  requirement: !ruby/object:Gem::Requirement