virtuatable 0.4.0 → 0.5.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: 0cd86829736be01f12a1db35c85f32513ad867d7d1da90653e5ea72daaab4b6c
4
- data.tar.gz: 91c4df3d59ad15bbd01863dda00b579dbfe036c784c1032811e38ad2be74afe0
3
+ metadata.gz: 514569bd58f7fea17204a3f89f5d0404286204311430bfe72c9d54e4c5c40886
4
+ data.tar.gz: 53c6187ab3c547bf9ce3ab5213db35606626cbc374eddc7ac65b6eef6e9361db
5
5
  SHA512:
6
- metadata.gz: a898038115a0536877da85e88106e41ddba528980ef1e5cd3ae19c2a6781ecf2e3ab91b63ef63de9a061cdcaf6409ad8a0fe7d2a3d791ef0e0244480cb316535
7
- data.tar.gz: db2d41f21c9da67b47394643485df87f90c8b0d8b9727ab0d3a8098ca84e4fc811cd47d2db264b2bb58b56413360609d97035818a2c867bda9728581e75afcee
6
+ metadata.gz: 2d4890c76a8ee25542c82a16c77bbb5b17e289f6c7ce2c4d2d5b1a3a3e91469f66f3db60f58dc35115dd76eba3713077f3b4e0a9b2758bc7a73aa3497c6a0a8c
7
+ data.tar.gz: 160aadc26b64faf46c7c3cb62a127db92b31888a5acea04497eaae1911c684a4848405c233af1517d9a67e0a56e37df2035c6c8b383dc42b5866329adc49e850
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Virtuatable
4
+ module API
5
+ # Modules holding the responses that are NOT errors.
6
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
7
+ module Responses
8
+ # Builds a list of items as a standard API response.
9
+ # The response will be a JSON hash containing two keys :
10
+ # - :count will hold the number of items displayed in the list
11
+ # - :items will hold the list of items.
12
+ # @param items [Array] the items to format as a standard API response.
13
+ def api_list(items)
14
+ halt 200, {
15
+ count: items.count,
16
+ items: items.map(&:to_h)
17
+ }.to_json
18
+ end
19
+
20
+ # Displays a creation standard response,
21
+ # returning the informations about the created item.
22
+ # @param item [Object] any object that responds to #to_h to display to the user.
23
+ def api_created(item)
24
+ halt 201, item.to_h.to_json
25
+ end
26
+
27
+ # Displays an item with the standards of the API.
28
+ # @param item [Object] the item to display as a JSON formatted hash.
29
+ def api_item(item)
30
+ halt 200, item.to_h.to_json
31
+ end
32
+
33
+ # Displays a message with a 200 status code
34
+ # @param message [String] the message to display with the API standards.
35
+ def api_ok(message)
36
+ api_item({message: message})
37
+ end
38
+ end
39
+ end
40
+ end
@@ -6,5 +6,6 @@ module Virtuatable
6
6
  # @author Vincent Courtois <courtois.vincent@outlook.com>
7
7
  module API
8
8
  autoload :Errors, 'virtuatable/api/errors'
9
+ autoload :Responses, 'virtuatable/api/responses'
9
10
  end
10
11
  end
@@ -19,7 +19,7 @@ module Virtuatable
19
19
  path: path,
20
20
  name: name
21
21
  )
22
- self.instance.builder = builder
22
+ instance.builder = builder
23
23
  builder.load!
24
24
  builder
25
25
  end
@@ -32,7 +32,7 @@ module Virtuatable
32
32
  path: path,
33
33
  name: name
34
34
  )
35
- self.instance.builder = builder
35
+ instance.builder = builder
36
36
  builder.load!
37
37
  builder
38
38
  end
@@ -81,8 +81,8 @@ module Virtuatable
81
81
  # Gets the loaders of the current class and all its ancestors that have loaders
82
82
  # @return [Array<Symbol>] the name of the loaders declared.
83
83
  def all_loaders
84
- superclasses = sanitized_ancestors.select do |ancestor|
85
- ancestor != self.class
84
+ superclasses = sanitized_ancestors.reject do |ancestor|
85
+ ancestor == self.class
86
86
  end
87
87
  ancestors_loaders = superclasses.map do |ancestor|
88
88
  ancestor.respond_to?(:loaders) ? ancestor.loaders : []
@@ -13,7 +13,7 @@ module Virtuatable
13
13
  # Declares a loader in the current builder class.
14
14
  # @param loader [Symbol] the name of the loader, infered as the method name to call.
15
15
  def declare_loader(loader, priority:)
16
- loader_h = {name: loader.to_sym, priority: priority}
16
+ loader_h = { name: loader.to_sym, priority: priority }
17
17
  @loaders.nil? ? @loaders = [loader_h] : @loaders << loader_h
18
18
  end
19
19
  end
@@ -23,7 +23,7 @@ module Virtuatable
23
23
  # Registers the service in the micro-services registry (consisting in
24
24
  # the arkaan_monitoring_services and arkaan_monitoring_instances collections)
25
25
  def load_registration!
26
- @service = Arkaan::Monitoring::Service.first_or_create!(
26
+ @service = Arkaan::Monitoring::Service.find_or_create_by!(
27
27
  key: @name,
28
28
  path: "/#{@name}"
29
29
  )
@@ -8,8 +8,9 @@ module Virtuatable
8
8
  class Base < Sinatra::Base
9
9
  register Sinatra::ConfigFile
10
10
  helpers Sinatra::CustomLogger
11
- # Includes the custom errors throwers.
11
+ # Includes the custom errors throwers and responses helpers.
12
12
  include Virtuatable::API::Errors
13
+ include Virtuatable::API::Responses
13
14
  # Includes the checking methods for sessions.
14
15
  include Virtuatable::Helpers::Sessions
15
16
  # Include the checkers and getters for the API gateway.
@@ -1,5 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Virtuatable
2
4
  module Helpers
5
+ # This module provides the #current_route method to get the current
6
+ # Arkaan::Monitoring::Route object from whithin sinatra routes.
7
+ # @author Vincent Courtois <courtois.vincent@outlook.com>
3
8
  module Routes
4
9
  def current_route
5
10
  splitted = request.env['sinatra.route'].split(' ')
@@ -10,4 +15,4 @@ module Virtuatable
10
15
  end
11
16
  end
12
17
  end
13
- end
18
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Virtuatable
2
4
  # This module holds all the logic for the specs tools for all micro services (shared examples and other things).
3
5
  # @author Vincent Courtois <courtois.vincent@outlook.com>
@@ -87,4 +89,4 @@ module Virtuatable
87
89
  end
88
90
  end
89
91
  end
90
- end
92
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Virtuatable
4
- VERSION = '0.4.0'
4
+ VERSION = '0.5.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: virtuatable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Courtois
@@ -360,6 +360,7 @@ files:
360
360
  - lib/virtuatable/api/errors/base.rb
361
361
  - lib/virtuatable/api/errors/forbidden.rb
362
362
  - lib/virtuatable/api/errors/not_found.rb
363
+ - lib/virtuatable/api/responses.rb
363
364
  - lib/virtuatable/application.rb
364
365
  - lib/virtuatable/builders.rb
365
366
  - lib/virtuatable/builders/base.rb