had 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8db267458f5bae36246d3f0a3b3b479d94884460
4
- data.tar.gz: 72b0dd4604f3b8bd240cdf96e459d5ef99047c1c
3
+ metadata.gz: 42ede04649baa5183ebe5f3de682f6b5b9456182
4
+ data.tar.gz: 49b469fdae7230489412c82f019ecd3b973705d6
5
5
  SHA512:
6
- metadata.gz: cdbcd9ff09cc012638b003ffc176dd17d19808b1daff08048837d1919ed3d5350f818d7eba34f4e50b819366da9d10294530441c50d43b11aff1750b0c044935
7
- data.tar.gz: 3951a608143dffd695a2447514d7baf47f676911009e3806e692526699b0f0a4a8887400a83d7450976efcdac3dcb605f556ced6fe00323bee88f8bf1b8e6983
6
+ metadata.gz: 58792ce4aa9616fe5316a492da9da5468d1c4fb2a651fdb5e084673427fc600d635a7eb21686e4c858d0a668590b16eab731d3ccc33089f5ec61dc6700412fb6
7
+ data.tar.gz: a8ded0d4a2adb62bab1a2a5ef047c42839732bd96450110e20726bfb9a05b710868e0aede00623b92a0001157c39bc3799aeecf12385aa4d926820f197b8b757
data/README.md CHANGED
@@ -20,7 +20,10 @@ If necessary, add `require "had"` to your `spec/spec_helper.rb` file
20
20
 
21
21
  ## Usage
22
22
 
23
- by default `had` is not active (this may be configured!). To activate it, run `rspec` with
23
+ Before start you need to setup environment.
24
+ `export APP_ROOT=/path/to/your/application`
25
+
26
+ By default `had` is not active (this may be configured!). To activate it, run `rspec` with
24
27
 
25
28
  `HAD_RUN=1 bundle exec rspec --order=defined`
26
29
 
@@ -34,9 +37,6 @@ Documentation will be put into your application's `/doc` folder
34
37
  # @param category[title] required String Category title
35
38
  # @param category[weight] in which order Category will be shown
36
39
  # param text may also be multiline
37
- # @method GET
38
- # @path /example/path
39
- # @host example.com
40
40
  def call(params)
41
41
  # action code
42
42
  end
data/lib/had/collector.rb CHANGED
@@ -77,8 +77,9 @@ module Had
77
77
  if request.params.env && (request_params = request.params)
78
78
  action = request.class.name.split('::').last
79
79
  controller = request.class.name.split('::')[-2]
80
- description, additional_info = get_action_description(controller, action)
80
+ description = get_action_description(controller, action)
81
81
  # description = request.class.to_s
82
+ routes_params = get_routes_params(controller, action)
82
83
  params = get_action_params(controller, action)
83
84
  query_parameters = request_params.to_h.reject { |p| %w[controller action format].include? p }
84
85
  backend_parameters = request_params.to_h.reject { |p| !%w[controller action format].include? p }
@@ -98,11 +99,11 @@ module Had
98
99
  description: description,
99
100
  params: params,
100
101
  request: {
101
- host: additional_info['host'],
102
- url: additional_info['host'] + additional_info['path'],
103
- path: additional_info['path'],
104
- symbolized_path: additional_info['host'] + additional_info['path'],
105
- method: additional_info['method'],
102
+ host: Had.host,
103
+ url: Had.host + routes_params['path'],
104
+ path: routes_params['path'],
105
+ symbolized_path: Had.host + routes_params['path'],
106
+ method: routes_params['method'],
106
107
  query_parameters: query_parameters,
107
108
  backend_parameters: backend_parameters,
108
109
  body: request.instance_variable_get("@_body"),
@@ -261,6 +262,23 @@ module Had
261
262
  ['not found']
262
263
  end
263
264
 
265
+ # returns routes information
266
+ # example TODO
267
+ def get_routes_params(controller, action)
268
+ lines = File.readlines(File.join(Had.root, 'config', 'routes.rb'))
269
+ data = {}
270
+
271
+ lines.each do |line|
272
+ if line.match(/\s*#{controller.downcase}##{action.downcase}/)
273
+ array = line.split(' ')
274
+ data['method'] = array[0].upcase
275
+ data['path'] = array[1].split("'")[1]
276
+ end
277
+ end
278
+
279
+ data
280
+ end
281
+
264
282
  # returns description action comments
265
283
  # example TODO
266
284
  def get_action_description(controller, action)
@@ -278,16 +296,10 @@ module Had
278
296
  break
279
297
  end
280
298
  end
281
- elsif line.match(/\s*# @method/)
282
- info['method'] = line.split(' ').last
283
- elsif line.match(/\s*# @path/)
284
- info['path'] = line.split(' ').last
285
- elsif line.match(/\s*# @host/)
286
- info['host'] = line.split(' ').last
287
299
  end
288
300
  end
289
301
 
290
- [description.join(' '), info]
302
+ description.join(' ')
291
303
  end
292
304
 
293
305
  # returns params action comments
@@ -20,12 +20,22 @@ module Had
20
20
  configuration.root
21
21
  end
22
22
 
23
+ def host
24
+ configuration.host
25
+ end
26
+
23
27
  class Configuration
24
28
  DEFAULT_FORMATTERS = %w(html json)
25
29
 
26
30
  def initialize
27
31
  Had.logger.level = Logger::INFO
28
32
 
33
+ if ENV['APP_HOST'].nil?
34
+ @host = "example.com"
35
+ else
36
+ @host = ENV['APP_HOST']
37
+ end
38
+
29
39
  if ENV['APP_ROOT'].nil?
30
40
  raise 'APP_ROOT is not defined'
31
41
  else
@@ -47,6 +57,6 @@ module Had
47
57
  attr_accessor :output_path
48
58
  attr_accessor :title
49
59
  attr_accessor :formatters
50
- attr_reader :root
60
+ attr_reader :root, :host
51
61
  end
52
62
  end
data/lib/had/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Had
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
data/lib/had.rb CHANGED
@@ -1,4 +1,3 @@
1
- require 'pry'
2
1
  require 'had/version'
3
2
  require 'had/utils'
4
3
  require 'had/configuration'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: had
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - nsheremet
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-13 00:00:00.000000000 Z
11
+ date: 2017-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coderay