intranet-core 2.2.0 → 2.3.0

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
  SHA256:
3
- metadata.gz: a6860141eca0145a6d51787a137641ead4978b69d2f7b2d28ce5dcf1a5193f42
4
- data.tar.gz: 6f43415cdf7334c81466b1205a838b92762c15dff3fb8ca3e096ccb71ebecfa2
3
+ metadata.gz: 16b200333caf9c9d025918b638960d84cc75214e4434bda26d4bd77d8f393301
4
+ data.tar.gz: 1f79effde4c5f7644226cb6667294814583fa09c8fc38bd895d2ca3ddf4eea66
5
5
  SHA512:
6
- metadata.gz: 84eeb50385f879656140e5b385a98a50c3149fa7b6cb8d31fd49b97ce73d5f69eda2e3e33789876196c0eaccaa47721b089e7870a0b90880392f03aedb279600
7
- data.tar.gz: 07e5122a4279dc99efe881651637e932ec36601b3007529e545b13b7ccaef2297ca05b7f6184f02a6693d61ad1147b162961c508992ce57ce09ce56a0a8de32e
6
+ metadata.gz: afa34d535755b7361b2b62a9b5824455652fc6d93d1e46f4d596f4bed09923ed3e1c7cf09ef6c05e92f615996d6ab4047626d052da61c6ef751c6751ed8227eb
7
+ data.tar.gz: f2abd667c22214dbe21a78417041a8b39aaec9a6e84f72cbfb423ded76ae58f416b61ffcf782e1427a63cc9435031068ccb2fc427c3d3a732131b76795cdac53
@@ -62,10 +62,10 @@ module CoreExtensions
62
62
  # (depth-first).
63
63
  # @return [String]
64
64
  def to_s(offset = '')
65
- str = offset + 'VALUE: ' + @value.to_s + "\n"
65
+ str = offset + "VALUE: #{@value}\n"
66
66
  @children_nodes.each do |id, node|
67
- str += offset + ' * ID: \'' + id.to_s + '\'' + "\n"
68
- str += node.to_s(offset + ' ')
67
+ str += offset + " * ID: '#{id}'\n"
68
+ str += node.to_s("#{offset} ")
69
69
  end
70
70
  str
71
71
  end
@@ -56,7 +56,7 @@ module Intranet
56
56
  raise Errno::EALREADY if @server.status != :Stop
57
57
 
58
58
  @builder.register(responder, path)
59
- module_add_servlet(path.empty? ? ['home'] : path, resources_dir)
59
+ module_add_servlet(path, resources_dir)
60
60
  module_add_locales(resources_dir)
61
61
  module_add_haml_templates(resources_dir)
62
62
  end
@@ -70,8 +70,8 @@ module Intranet
70
70
 
71
71
  # Starts the web server.
72
72
  def start
73
- @logger.info('Intranet::Core: using locale \'' + I18n.default_locale.to_s + '\'')
74
- @logger.info('Intranet::Core: running Intranet version ' + VERSION)
73
+ @logger.info("Intranet::Core: using locale '#{I18n.default_locale}'")
74
+ @logger.info("Intranet::Core: running Intranet version #{VERSION}")
75
75
  # Start serving HTTP requests
76
76
  @server.start
77
77
  end
@@ -115,7 +115,7 @@ module Intranet
115
115
  end
116
116
 
117
117
  def module_add_servlet(path, resources_dir)
118
- @server.mount('/' + path.join('/') + '/design',
118
+ @server.mount("/#{path.join('/')}/design",
119
119
  WEBrick::HTTPServlet::FileHandler,
120
120
  File.join(resources_dir, 'www'))
121
121
  end
@@ -38,7 +38,7 @@ module Intranet
38
38
  @responders.to_h.each do |path, responder|
39
39
  next if responder.nil?
40
40
 
41
- @logger.debug('Intranet::Builder: finalize responder at \'' + path + '\'')
41
+ @logger.debug("Intranet::Builder: finalize responder at '#{path}'")
42
42
  responder.finalize
43
43
  end
44
44
  end
@@ -108,7 +108,7 @@ module Intranet
108
108
  end
109
109
  end
110
110
 
111
- [current_treenode.value, '/' + parsed_path.join('/'), '/' + unparsed_path.join('/')]
111
+ [current_treenode.value, "/#{parsed_path.join('/')}", "/#{unparsed_path.join('/')}"]
112
112
  end
113
113
 
114
114
  # Encapsulate the given body in the default page skeleton, effectively
@@ -121,7 +121,8 @@ module Intranet
121
121
  js: responder.js_dependencies, current_path: path)
122
122
  end
123
123
 
124
- # Check whether a path is valid.
124
+ # Check whether a path is valid. In particular, this function excludes a path containing an
125
+ # empty ('') or dot ('.') part, for instance '/path//to/./responder'.
125
126
  # @param path [Array] The path to test.
126
127
  # @return [Boolean] True if the path is valid, False otherwise.
127
128
  def valid_path?(path)
@@ -137,8 +138,6 @@ module Intranet
137
138
  def insert_responder(responder, path)
138
139
  current_node = @responders
139
140
  path.each do |part|
140
- next if part.empty? || part == '.'
141
-
142
141
  current_node = current_node.add_child_node(part)
143
142
  end
144
143
  current_node.value = responder
@@ -50,7 +50,7 @@ module Intranet
50
50
  # @return [String] The path to the template if it exists, an empty string otherwise.
51
51
  def find_template(template)
52
52
  HamlWrapper.load_path.each do |dir|
53
- candidate = File.join(dir, template + '.haml')
53
+ candidate = File.join(dir, "#{template}.haml")
54
54
  return candidate if File.exist?(candidate)
55
55
  end
56
56
  ''
@@ -6,7 +6,7 @@ module Intranet
6
6
  NAME = 'intranet-core'
7
7
 
8
8
  # The version of the gem, according to semantic versionning.
9
- VERSION = '2.2.0'
9
+ VERSION = '2.3.0'
10
10
 
11
11
  # The URL of the gem homepage.
12
12
  HOMEPAGE_URL = 'https://rubygems.org/gems/intranet-core'
@@ -26,7 +26,7 @@ module Intranet
26
26
  # @param level The level of the message
27
27
  # @param msg [String] The message
28
28
  def log(level, msg)
29
- super(level, COLOR[level] + Time.now.strftime('[%Y-%m-%d %H:%M:%S] ') + msg + "\033[0m")
29
+ super(level, "#{COLOR[level]}#{Time.now.strftime('[%Y-%m-%d %H:%M:%S]')} #{msg}\033[0m")
30
30
  end
31
31
 
32
32
  # Logs an object that responds to +to_s+ at level INFO.
@@ -37,20 +37,12 @@ RSpec.describe Intranet::Core::HamlWrapper do
37
37
  end
38
38
 
39
39
  context 'if the template is not found in path' do
40
- before do
41
- described_class.load_path = [] # empty load path
42
- expect(described_class.load_path).to be_empty
43
- end
44
-
45
40
  it 'should return an empty string' do
46
41
  expect(included.new.to_markup('')).to be_empty
47
42
  expect(extended.to_markup('')).to be_empty
48
43
 
49
44
  expect(included.new.to_markup('unknown')).to be_empty
50
45
  expect(extended.to_markup('unknown')).to be_empty
51
-
52
- expect(included.new.to_markup('title_and_breadcrumb')).to be_empty
53
- expect(extended.to_markup('title_and_breadcrumb')).to be_empty
54
46
  end
55
47
  end
56
48
 
@@ -152,7 +152,7 @@ RSpec.describe Intranet::Core do
152
152
 
153
153
  it 'should be used to serve URI relative to the module root' do
154
154
  socket = TCPSocket.new('localhost', @intranet.port)
155
- socket.puts("GET /responder/index.html HTTP/1.1\r\n" \
155
+ socket.puts("GET /responder/ HTTP/1.1\r\n" \
156
156
  "Host: localhost:#{@intranet.port}\r\n\r\n")
157
157
  expect(socket.gets).to include('HTTP/1.1 200 OK')
158
158
  socket.close
@@ -264,7 +264,7 @@ RSpec.describe Intranet::Core do
264
264
 
265
265
  # Returned HTML document: includes Intranet Core name, version and URL
266
266
  expect(html).to match(
267
- %r{<footer>.*<a href='#{Intranet::Core::HOMEPAGE_URL}'.*>#{Intranet::Core::NAME}</a>.*#{Intranet::Core::VERSION}.*</footer>}m # rubocop:disable Layout/LineLength
267
+ %r{<footer>.*<a href='#{Intranet::Core::HOMEPAGE_URL}'.*>#{Intranet::Core::NAME}</a>.*#{Intranet::Core::VERSION}.*</footer>}m
268
268
  )
269
269
 
270
270
  # Returned HTML document: includes all registered modules version name, version and URL
@@ -18,7 +18,7 @@ RSpec.describe Intranet::Logger do
18
18
  @logger = described_class.new
19
19
  end
20
20
 
21
- TEST_CASES = [
21
+ test_cases = [
22
22
  {
23
23
  level: described_class::FATAL, level_str: 'FATAL', level_method: :fatal,
24
24
  displayed: {
@@ -81,9 +81,9 @@ RSpec.describe Intranet::Logger do
81
81
  }
82
82
  ].freeze
83
83
 
84
- TEST_CASES.each do |tc|
85
- context 'given a ' + tc[:level_str] + ' message' do
86
- it 'should only be displayed if logger level is at least ' + tc[:level_str] do
84
+ test_cases.each do |tc|
85
+ context "given a #{tc[:level_str]} message" do
86
+ it "should only be displayed if logger level is at least #{tc[:level_str]}" do
87
87
  tc[:displayed].each do |level, displayed|
88
88
  @logger.level = level
89
89
  if displayed
@@ -112,7 +112,7 @@ RSpec.describe Intranet::Logger do
112
112
  .to_stderr_from_any_process
113
113
  end
114
114
 
115
- it 'should be colored in ' + tc[:color_desc] do
115
+ it "should be colored in #{tc[:color_desc]}" do
116
116
  @logger.level = tc[:level]
117
117
  expect { @logger.log(tc[:level], 'TEST_MSG') }
118
118
  .to output(tc[:color_regex]).to_stderr_from_any_process
@@ -43,8 +43,11 @@ RSpec.configure do |config|
43
43
  # Load and start SimpleCov to gather code coverage information
44
44
  unless config.files_to_run.one?
45
45
  require 'simplecov'
46
- SimpleCov.add_filter 'spec' # exclude 'spec' folder from coverage
47
- SimpleCov.start
48
- require 'intranet/core'
46
+ SimpleCov.start do
47
+ enable_coverage :branch # measure branches coverage
48
+ primary_coverage :branch
49
+ minimum_coverage line: 100, branch: 100 # minimal coverage rate to succeed
50
+ add_filter 'spec' # exclude 'spec' folder from coverage
51
+ end
49
52
  end
50
53
  end
@@ -6,7 +6,7 @@ module Intranet
6
6
  class TestResponder < AbstractResponder
7
7
  attr_reader :finalized
8
8
 
9
- def initialize(responses = {}, extra_css = [], extra_js = [], hide_from_menu = false)
9
+ def initialize(responses = {}, extra_css = [], extra_js = [], hide_from_menu = false) # rubocop:disable Metrics/ParameterLists
10
10
  @responses = responses
11
11
  @extra_css = extra_css
12
12
  @extra_js = extra_js
@@ -37,10 +37,6 @@ module Intranet
37
37
  'http://nil/'
38
38
  end
39
39
 
40
- def resources_dir
41
- super
42
- end
43
-
44
40
  def generate_page(path, query)
45
41
  if path.start_with?('/query')
46
42
  [200, 'text/plain', dump_with_encoding(path, query)]
@@ -62,7 +58,7 @@ module Intranet
62
58
  private
63
59
 
64
60
  def dump_with_encoding(path, query)
65
- "PATH=#{path} (#{path.encoding}), QUERY={" +
61
+ "PATH=#{path} (#{path.encoding}), QUERY={" + # rubocop:disable Style/StringConcatenation
66
62
  query.map { |k, v| "#{k} (#{k.encoding}) => #{v} (#{v.encoding})" }.join(',') +
67
63
  "}\r\n"
68
64
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intranet-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ebling Mis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-02 00:00:00.000000000 Z
11
+ date: 2021-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: haml
@@ -112,30 +112,30 @@ dependencies:
112
112
  name: rubocop
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - "~>"
115
+ - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: 0.81.0
117
+ version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - "~>"
122
+ - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: 0.81.0
124
+ version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: simplecov
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '0'
131
+ version: '0.21'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '0'
138
+ version: '0.21'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: yard
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -204,7 +204,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
204
204
  requirements:
205
205
  - - "~>"
206
206
  - !ruby/object:Gem::Version
207
- version: '2.3'
207
+ version: '2.5'
208
208
  required_rubygems_version: !ruby/object:Gem::Requirement
209
209
  requirements:
210
210
  - - ">="