reality-core 1.6.0 → 1.7.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
  SHA1:
3
- metadata.gz: 43244fb34b6e74b1281a583f71cdd1ba308391ce
4
- data.tar.gz: 1cdbdaf9304e69c358f6f7448164cfcb84932e91
3
+ metadata.gz: bf10a8b1576f27d3beba03b573a146bd855224e2
4
+ data.tar.gz: e304fccd1db55c4dc6add1c28b1b3197ceb0cdd0
5
5
  SHA512:
6
- metadata.gz: eb5958c12e4396ac98014749fc3063482d3822f5a1a0769ae70964a293ff7d2b6c82f0be585c2f958250781f3f78882d5d5bb02938727516cf2b68e99d56f18e
7
- data.tar.gz: 8b7750bacc77d561bc64578d0d6775a29edb00262e3cede212da6d1a713f4e43090f897cae29550ca471dc7fdf14b8bdf3fe08de0baa85bef6c31070179c680e
6
+ metadata.gz: 0ec117eedcdbe4551264e49a48713a2cc61d050aa2c085876856437bd5e2e9056368515f936e6ca428aecbab5d3f8bd9316ab28c09de87b4ca19f20ca111713d
7
+ data.tar.gz: 629348057bbcdcc2bdec49df364c2629388d99286d68f7a458bad99b7b94a970dee1058dce54017960e5cff9ef2df9d5f9a07136150bbb88a44f829899de1d85
data/lib/reality/core.rb CHANGED
@@ -14,3 +14,4 @@
14
14
 
15
15
  require 'reality/base_element'
16
16
  require 'reality/logging'
17
+ require 'reality/options'
@@ -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
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{reality-core}
5
- s.version = '1.6.0'
5
+ s.version = '1.7.0'
6
6
  s.platform = Gem::Platform::RUBY
7
7
 
8
8
  s.authors = ['Peter Donald']
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
- assert_raise(Test::Unit::AssertionFailedError.new("<\"Hello from log system\\n\"> expected but was\n<\"\">.")) do
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
- assert_raise(Test::Unit::AssertionFailedError.new('<RuntimeError(<Hello from log system>)> exception expected but none was thrown.')) do
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.6.0
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-24 00:00:00.000000000 Z
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: {}