micro_api 0.1.1 → 0.1.2

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: 88d34ac6588812baff48c14c12b1ab5dac85de8ce875a633b10ed557fd207319
4
- data.tar.gz: '0924c15c703900c1fb9f90387bd1af51da634ca1d52bc4eae3436b93080cc954'
3
+ metadata.gz: 931fe90b19dce2b382d2bf2a9aaa8c8387d8e473cd12ce31a9f9c7faa74cd10b
4
+ data.tar.gz: '091df9223364158ce18f3adaf343e8ee42c62df40b0e2745af75e8d1e132d7be'
5
5
  SHA512:
6
- metadata.gz: e792082eb0e8dddfd11db78b6f8ffe85219851d7599fb1c1c0035803ae9de121985cab7a5f61b79ff568a0a0597b94b772a8c8fe1140f08ade427acc8260c0be
7
- data.tar.gz: 523a47666b6ab4affed06d1fd0e3c30b52e7a0c9409d246ddc8f811b893a65fb219a51b874db5830ee3c397e530d511e39eff49641562b0be8b4a08edb37c162
6
+ metadata.gz: c1fb1c1fa9ec7b39e6f37ce75493e0d0ebc5693d107d93cedf259771d444b0b11aca0e850eafa00ad5ae2caa72b9245d92a7314c6f95df3366009250545243b5
7
+ data.tar.gz: 452621f6f949ccaa271e62952ea28708841d1e589fff4268fbd223c5fae47486eee3bf741b42db0995a67cae650522e0a04b07dc541cd57611183ea1325fa438
@@ -30,8 +30,13 @@ module MicroApi
30
30
 
31
31
  desc "This generator add row in application.rb file"
32
32
  def generate_micro_api_application
33
- application 'config.active_record.default_timezone = :utc' if defined?(ActiveRecord)
34
- application 'config.time_zone = "CET"'
33
+ application_list = ["\n"]
34
+ application_list << "config.active_record.default_timezone = :utc" if defined?(ActiveRecord)
35
+ application_list << "config.time_zone = 'CET'"
36
+
37
+ inject_into_file 'config/application.rb', before: /\n end$/ do
38
+ application_list.join("\n ").gsub(" \n", "\n")
39
+ end
35
40
  end
36
41
 
37
42
  desc "This generator creates an initializer file at config/initializers"
@@ -40,10 +45,24 @@ module MicroApi
40
45
  template "staging.rb", "#{Rails.root}/config/environments/staging.rb"
41
46
  end
42
47
 
43
- desc "This generator add row in routes.rb file"
44
- def generate_micro_api_route
45
- route "mount MicroApi::Engine, at: MicroApi.routes_path, as: '#{MicroApi.routes_path}'"
46
- route "match '*path', to: 'micro_api/static#no_route_matches', via: :all"
48
+ desc "This generator add 'api namespace' rows in routes.rb file"
49
+ def generate_micro_api_route_api_namespace
50
+ inject_into_file 'config/routes.rb', before: " # Defines the root path route" do
51
+ " namespace :api, defaults: { format: :json } do\n end\n\n"
52
+ end
53
+ end
54
+
55
+ desc "This generator add final rows in routes.rb file"
56
+ def generate_micro_api_route_last
57
+ routes_list = [
58
+ "\n",
59
+ "mount MicroApi::Engine, at: MicroApi.routes_path, as: '#{MicroApi.routes_path}'",
60
+ "match '*path', to: 'micro_api/static#no_route_matches', via: :all"
61
+ ]
62
+
63
+ inject_into_file 'config/routes.rb', before: /\nend$/ do
64
+ routes_list.join("\n ").gsub(" \n", "\n")
65
+ end
47
66
  end
48
67
  end
49
68
  end
@@ -1,8 +1,34 @@
1
+ require 'lograge'
2
+
1
3
  module MicroApi
2
4
  class Engine < ::Rails::Engine
3
5
  isolate_namespace MicroApi
4
6
  config.generators.api_only = true
5
7
 
8
+ initializer "micro_api.lograge.init" do |app|
9
+ app.configure do
10
+ config.lograge.enabled = true
11
+ config.lograge.base_controller_class = "ActionController::API"
12
+ config.lograge.formatter = Lograge::Formatters::Json.new
13
+ config.colorize_logging = false
14
+ config.lograge.logger = ActiveSupport::Logger.new($stdout)
15
+
16
+ config.lograge.ignore_custom = lambda do |event|
17
+ event.payload[:path] == "#{MicroApi.routes_path}/healthz" && event.payload[:request].remote_ip =~ /^10\./
18
+ end
19
+ config.lograge.custom_payload do |controller|
20
+ {
21
+ level: :info,
22
+ log_type: :rails,
23
+ request_id: controller.request.request_id,
24
+ host: controller.request.host,
25
+ remote_ip: controller.request.remote_ip,
26
+ image_tag: ENV['IMAGE_TAG']
27
+ }
28
+ end
29
+ end
30
+ end
31
+
6
32
  config.generators do |g|
7
33
  g.test_framework :rspec,
8
34
  controller_specs: true,
@@ -1,3 +1,3 @@
1
1
  module MicroApi
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -38,6 +38,6 @@ module Dummy
38
38
 
39
39
  config.hosts << "www.example.com"
40
40
 
41
- config.time_zone = "CET"
41
+ config.time_zone = 'CET'
42
42
  end
43
43
  end
@@ -1,5 +1,14 @@
1
1
  Rails.application.routes.draw do
2
+ # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
3
+
4
+ namespace :api, defaults: { format: :json } do
5
+ end
6
+
7
+ # Defines the root path route ("/")
8
+ # root "articles#index"
9
+
2
10
  # mount MicroApi::Engine => "/micro_api"
11
+
3
12
  mount MicroApi::Engine, at: MicroApi.routes_path, as: '/mse'
4
13
  match '*path', to: 'micro_api/static#no_route_matches', via: :all
5
14
  end
@@ -4,6 +4,12 @@ RSpec.describe "Statics" do
4
4
  describe "GET /healthz" do
5
5
  before { @route = get("#{MicroApi.routes_path}/healthz") }
6
6
 
7
+ it "returns http success", type: :request do
8
+ expect(response).to have_http_status(:success)
9
+ expect(response.header['Content-Type']).to include 'application/json'
10
+ expect(json).to have_key('status')
11
+ end
12
+
7
13
  it "routes /micro_api/version to the static controller", type: :routing do
8
14
  expect(@route).to route_to(
9
15
  controller: 'micro_api/static',
@@ -11,10 +17,5 @@ RSpec.describe "Statics" do
11
17
  format: :json
12
18
  )
13
19
  end
14
- it "returns http success", type: :request do
15
- expect(response).to have_http_status(:success)
16
- expect(response.header['Content-Type']).to include 'application/json'
17
- expect(json).to have_key('status')
18
- end
19
20
  end
20
21
  end
metadata CHANGED
@@ -1,31 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micro_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-25 00:00:00.000000000 Z
11
+ date: 2023-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 6.0.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 6.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.48'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.48'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -39,13 +53,13 @@ dependencies:
39
53
  - !ruby/object:Gem::Version
40
54
  version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
- name: simplecov
56
+ name: lograge
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
59
  - - ">="
46
60
  - !ruby/object:Gem::Version
47
61
  version: '0'
48
- type: :development
62
+ type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
@@ -107,8 +121,6 @@ files:
107
121
  - spec/dummy/config/locales/en.yml
108
122
  - spec/dummy/config/puma.rb
109
123
  - spec/dummy/config/routes.rb
110
- - spec/dummy/log/development.log
111
- - spec/dummy/tmp/development_secret.txt
112
124
  - spec/generator/micro_api/installs_generator_spec.rb
113
125
  - spec/rails_helper.rb
114
126
  - spec/requests/micro_api/static_healthz_spec.rb
@@ -125,7 +137,7 @@ metadata:
125
137
  homepage_uri: https://github.com/lelered/micro_api
126
138
  source_code_uri: https://github.com/lelered/micro_api
127
139
  changelog_uri: https://github.com/lelered/micro_api/blob/main/CHANGELOG.md
128
- post_install_message:
140
+ post_install_message:
129
141
  rdoc_options: []
130
142
  require_paths:
131
143
  - lib
@@ -140,8 +152,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
152
  - !ruby/object:Gem::Version
141
153
  version: '0'
142
154
  requirements: []
143
- rubygems_version: 3.4.9
144
- signing_key:
155
+ rubygems_version: 3.4.10
156
+ signing_key:
145
157
  specification_version: 4
146
158
  summary: Engine plugin for Ruby on Rails applications
147
159
  test_files:
@@ -163,8 +175,6 @@ test_files:
163
175
  - spec/dummy/config/puma.rb
164
176
  - spec/dummy/config/routes.rb
165
177
  - spec/dummy/config.ru
166
- - spec/dummy/log/development.log
167
- - spec/dummy/tmp/development_secret.txt
168
178
  - spec/generator/micro_api/installs_generator_spec.rb
169
179
  - spec/rails_helper.rb
170
180
  - spec/requests/micro_api/static_healthz_spec.rb