reality-core 1.6.0 → 1.7.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 +4 -4
- data/lib/reality/core.rb +1 -0
- data/lib/reality/options.rb +37 -0
- data/reality-core.gemspec +1 -1
- data/test/test_logging.rb +2 -2
- data/test/test_options.rb +23 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: bf10a8b1576f27d3beba03b573a146bd855224e2
|
|
4
|
+
data.tar.gz: e304fccd1db55c4dc6add1c28b1b3197ceb0cdd0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0ec117eedcdbe4551264e49a48713a2cc61d050aa2c085876856437bd5e2e9056368515f936e6ca428aecbab5d3f8bd9316ab28c09de87b4ca19f20ca111713d
|
|
7
|
+
data.tar.gz: 629348057bbcdcc2bdec49df364c2629388d99286d68f7a458bad99b7b94a970dee1058dce54017960e5cff9ef2df9d5f9a07136150bbb88a44f829899de1d85
|
data/lib/reality/core.rb
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
# you may not use this file except in compliance with the License.
|
|
4
|
+
# You may obtain a copy of the License at
|
|
5
|
+
#
|
|
6
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
#
|
|
8
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
# See the License for the specific language governing permissions and
|
|
12
|
+
# limitations under the License.
|
|
13
|
+
#
|
|
14
|
+
|
|
15
|
+
module Reality
|
|
16
|
+
module Options
|
|
17
|
+
class << self
|
|
18
|
+
# Set the levels on an array of loggers.
|
|
19
|
+
# The levels parameter must be an array matching the number of loggers supplied or a single level.
|
|
20
|
+
# If a block is supplied then the levels are set to the specified values for the duration of the
|
|
21
|
+
# block and then reset to original values after the block completes.
|
|
22
|
+
def check(options, valid_options, logging_container = nil, method_descriptor = nil)
|
|
23
|
+
bad_options = options.keys.select { |k| !valid_options.include?(k) }
|
|
24
|
+
return if bad_options.empty?
|
|
25
|
+
|
|
26
|
+
single_error = bad_options.size == 1
|
|
27
|
+
message = "Unknown option#{single_error ? '' : 's'} #{single_error ? "'#{bad_options.first.inspect}'" : bad_options.inspect} passed to #{method_descriptor || 'method'}"
|
|
28
|
+
if logging_container
|
|
29
|
+
logging_container.error(message)
|
|
30
|
+
else
|
|
31
|
+
raise ArgumentError.new(message)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
data/reality-core.gemspec
CHANGED
data/test/test_logging.rb
CHANGED
|
@@ -103,13 +103,13 @@ class Reality::TestLogging < Reality::TestCase
|
|
|
103
103
|
MyModule2.info('Hello from log system')
|
|
104
104
|
end
|
|
105
105
|
|
|
106
|
-
|
|
106
|
+
assert_raise_kind_of(Test::Unit::AssertionFailedError) do
|
|
107
107
|
mytest.assert_logging_message(MyModule2, 'Hello from log system') do
|
|
108
108
|
# There is no message
|
|
109
109
|
end
|
|
110
110
|
end
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
assert_raise_kind_of(Test::Unit::AssertionFailedError) do
|
|
113
113
|
mytest.assert_logging_error(MyModule2, 'Hello from log system') do
|
|
114
114
|
# Should fail as there is only a message and not an error
|
|
115
115
|
MyModule2.info('Hello from log system')
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require File.expand_path('../helper', __FILE__)
|
|
2
|
+
|
|
3
|
+
class Reality::TestOptions < Reality::TestCase
|
|
4
|
+
|
|
5
|
+
module MyModule
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def test_basic_operation
|
|
9
|
+
|
|
10
|
+
Reality::Options.check({}, [:a, :b, :c])
|
|
11
|
+
|
|
12
|
+
assert_raise(ArgumentError.new("Unknown option ':z' passed to method")) { Reality::Options.check({:a => 1, :z => 'x'}, [:a, :b, :c]) }
|
|
13
|
+
assert_raise(ArgumentError.new('Unknown options [:x, :z] passed to method')) { Reality::Options.check({:x => 1, :z => 'x'}, [:a, :b, :c]) }
|
|
14
|
+
assert_raise(ArgumentError.new('Unknown options [:x, :z] passed to initializer')) { Reality::Options.check({:x => 1, :z => 'x'}, [:a, :b, :c], nil, 'initializer') }
|
|
15
|
+
|
|
16
|
+
io = StringIO.new('', 'w')
|
|
17
|
+
Reality::Logging.configure(MyModule, ::Logger::INFO, io)
|
|
18
|
+
|
|
19
|
+
assert_raise(RuntimeError.new('Unknown options [:x, :z] passed to initializer')) { Reality::Options.check({:x => 1, :z => 'x'}, [:a, :b, :c], MyModule, 'initializer') }
|
|
20
|
+
|
|
21
|
+
assert_equal "Unknown options [:x, :z] passed to initializer\n", io.string
|
|
22
|
+
end
|
|
23
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: reality-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Peter Donald
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-12-
|
|
11
|
+
date: 2016-12-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|
|
@@ -56,10 +56,12 @@ files:
|
|
|
56
56
|
- lib/reality/base_element.rb
|
|
57
57
|
- lib/reality/core.rb
|
|
58
58
|
- lib/reality/logging.rb
|
|
59
|
+
- lib/reality/options.rb
|
|
59
60
|
- reality-core.gemspec
|
|
60
61
|
- test/helper.rb
|
|
61
62
|
- test/test_base_element.rb
|
|
62
63
|
- test/test_logging.rb
|
|
64
|
+
- test/test_options.rb
|
|
63
65
|
homepage: https://github.com/realityforge/reality-core
|
|
64
66
|
licenses: []
|
|
65
67
|
metadata: {}
|