micro_api 0.1.0 → 0.1.1

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: 760d9919d69b54e4fedf75c0d33c3e5fd92b40b90d276f0c5b03957e59c1cc03
4
- data.tar.gz: f4d1dbd92376d089ba6e1dbc2ec68b4f4a7f19c9dd6da4c98c991533ec8dfc49
3
+ metadata.gz: 88d34ac6588812baff48c14c12b1ab5dac85de8ce875a633b10ed557fd207319
4
+ data.tar.gz: '0924c15c703900c1fb9f90387bd1af51da634ca1d52bc4eae3436b93080cc954'
5
5
  SHA512:
6
- metadata.gz: 6f18a322f332c97f230b3cd92dcd5a674b74556c3c3ddbccd45fc2afcd8546661924e61d8e7d70dcc09648eecf07baac78da4dc0517852b8081fbe778bb24831
7
- data.tar.gz: 6fbe29b7dd071e6d80d7f64c28e32e9bf4f04c615a74fe9b6c954ac2b6df93aed373efec7ed66ec60ceffc0c2d1ed3a678ae37bc204be402d4e2cb3f8e21fda6
6
+ metadata.gz: e792082eb0e8dddfd11db78b6f8ffe85219851d7599fb1c1c0035803ae9de121985cab7a5f61b79ff568a0a0597b94b772a8c8fe1140f08ade427acc8260c0be
7
+ data.tar.gz: 523a47666b6ab4affed06d1fd0e3c30b52e7a0c9409d246ddc8f811b893a65fb219a51b874db5830ee3c397e530d511e39eff49641562b0be8b4a08edb37c162
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # MicroApi
2
- Short description and motivation.
2
+ This is a Rails plugin that would like to help the startup of rails applications oriented to microservices or, in general, application deployed on the cloud.
3
3
 
4
4
  ## Usage
5
5
  How to use my plugin.
@@ -13,7 +13,8 @@ gem "micro_api"
13
13
 
14
14
  And then execute:
15
15
  ```bash
16
- $ bundle
16
+ bundle
17
+ bundle exec rails generate micro_api:install
17
18
  ```
18
19
 
19
20
  Or install it yourself as:
@@ -12,5 +12,10 @@ module MicroApi
12
12
  itag: ENV.fetch("IMAGE_TAG", nil), # image tag
13
13
  }
14
14
  end
15
+
16
+ def no_route_matches
17
+ exception = ActionController::RoutingError.new("No route matches [#{request.method}] #{request.path}")
18
+ render json: { error: exception.message }, status: :not_found
19
+ end
15
20
  end
16
21
  end
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Main installation generator.
3
+
4
+ Example:
5
+ bin/rails generate micro_api:install
6
+
7
+ This will create:
8
+ - config/initializers/micro_api.rb
9
+ - config/environments/staging.rb
@@ -0,0 +1,49 @@
1
+ module MicroApi
2
+ # main generator installer
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path("templates", __dir__)
5
+
6
+ argument :component, type: :string, default: 'all',
7
+ banner: "all|application|initializer|route"
8
+
9
+ def main
10
+ method_name = "generate_micro_api_#{component}"
11
+ return unless self.class.private_method_defined?(method_name)
12
+
13
+ send(method_name)
14
+ end
15
+
16
+ private
17
+
18
+ def local_methods
19
+ private_methods.select { |e| e.to_s.include? "generate_micro_api_" }
20
+ end
21
+
22
+ desc "This generator creates all installs"
23
+ def generate_micro_api_all
24
+ local_methods.each do |method_name|
25
+ next if method_name == __method__
26
+
27
+ send(method_name)
28
+ end
29
+ end
30
+
31
+ desc "This generator add row in application.rb file"
32
+ def generate_micro_api_application
33
+ application 'config.active_record.default_timezone = :utc' if defined?(ActiveRecord)
34
+ application 'config.time_zone = "CET"'
35
+ end
36
+
37
+ desc "This generator creates an initializer file at config/initializers"
38
+ def generate_micro_api_initializer
39
+ template "micro_api.rb", "#{Rails.root}/config/initializers/micro_api.rb"
40
+ template "staging.rb", "#{Rails.root}/config/environments/staging.rb"
41
+ end
42
+
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"
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,5 @@
1
+ require 'micro_api'
2
+
3
+ MicroApi.setup do |config|
4
+ config.routes_path = "/mse"
5
+ end
@@ -0,0 +1,5 @@
1
+ require_relative "production"
2
+
3
+ Rails.application.configure do
4
+ # Your overriders goes here...
5
+ end
@@ -1,3 +1,3 @@
1
1
  module MicroApi
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
data/lib/micro_api.rb CHANGED
@@ -2,5 +2,12 @@ require "micro_api/version"
2
2
  require "micro_api/engine"
3
3
 
4
4
  module MicroApi
5
- # Your code goes here...
5
+
6
+ mattr_accessor :routes_path
7
+ @@routes_path = "/mse"
8
+
9
+ def self.setup
10
+ yield self
11
+ end
12
+
6
13
  end
@@ -37,5 +37,7 @@ module Dummy
37
37
  config.api_only = true
38
38
 
39
39
  config.hosts << "www.example.com"
40
+
41
+ config.time_zone = "CET"
40
42
  end
41
43
  end
@@ -1,3 +1,5 @@
1
1
  Rails.application.routes.draw do
2
- mount MicroApi::Engine => "/micro_api"
2
+ # mount MicroApi::Engine => "/micro_api"
3
+ mount MicroApi::Engine, at: MicroApi.routes_path, as: '/mse'
4
+ match '*path', to: 'micro_api/static#no_route_matches', via: :all
3
5
  end