pantheios-ruby 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+
2
+ module Pantheios
3
+ module Services
4
+
5
+ class SimpleConsoleService
6
+
7
+ def severity_logged? severity
8
+
9
+ true
10
+ end
11
+
12
+ def log sev, t, pref, msg
13
+
14
+ $stderr.puts "#{pref}#{msg}"
15
+ end
16
+ end
17
+
18
+ end # module Services
19
+ end # module Pantheios
20
+
@@ -0,0 +1,5 @@
1
+
2
+ require 'pantheios/util/process_util'
3
+ require 'pantheios/util/thread_util'
4
+ require 'pantheios/util/version_util'
5
+
@@ -0,0 +1,22 @@
1
+
2
+ module Pantheios
3
+ module Util
4
+
5
+ module ProcessUtil
6
+
7
+ def self.derive_process_name dollar0 = nil
8
+
9
+ dollar0 ||= $0
10
+
11
+ bn = File.basename dollar0
12
+
13
+ bn =~ /\.rb$/ ? $` : bn
14
+ end
15
+
16
+ end # module ProcessUtil
17
+
18
+ end # module Util
19
+ end # module Pantheios
20
+
21
+
22
+
@@ -0,0 +1,83 @@
1
+
2
+ module Pantheios
3
+ module Util
4
+
5
+ module ThreadUtil
6
+
7
+ # Creates (if necessary) and sets the given thread's +thread_name+
8
+ # attribute to the given name
9
+ #
10
+ # === Signature
11
+ #
12
+ # * *Parameters:*
13
+ # - +t+ [Thread, nil] The thread to be named, or +nil+ if it should
14
+ # operate on the current (invoking) thread
15
+ # - +name+ [String] The thread's name
16
+ def self.set_thread_name t, name
17
+
18
+ t ||= Thread.current
19
+
20
+ class << t; attr_accessor :thread_name; end unless t.respond_to? :thread_name
21
+
22
+ t.thread_name = name
23
+ end
24
+
25
+ def self.get_thread_name t
26
+
27
+ t ||= Thread.current
28
+
29
+ return t.thread_name if t.respond_to? :thread_name
30
+
31
+ t.to_s
32
+ end
33
+
34
+ # Inclusion module for giving the included type the +thread_name+
35
+ # attribute
36
+ #
37
+ # If included into a thread type, or a thread instance, then
38
+ module ThreadName
39
+
40
+ def self.included receiver
41
+
42
+ if receiver < ::Thread
43
+
44
+ receiver.instance_eval do
45
+
46
+ define_method(:thread_name) { @thread_name || self.to_s }
47
+ define_method(:thread_name=) { |name| @thread_name = name }
48
+ end
49
+ else
50
+
51
+ receiver.instance_eval do
52
+
53
+ define_method :thread_name do |name = (name_not_given_ = true)|
54
+
55
+ t = Thread.current
56
+
57
+ has_tn = t.respond_to? :thread_name
58
+
59
+ if name_not_given_
60
+
61
+ return t.thread_name if has_tn
62
+
63
+ t.to_s
64
+ else
65
+
66
+ class << t; attr_accessor :thread_name; end unless has_tn
67
+
68
+ t.thread_name = name
69
+ end
70
+ end
71
+
72
+ define_method(:thread_name=) { |name| thread_name name }
73
+ end
74
+ end
75
+ end
76
+ end
77
+
78
+ end # module ThreadUtil
79
+
80
+ end # module Util
81
+ end # module Pantheios
82
+
83
+
@@ -0,0 +1,44 @@
1
+
2
+ module Pantheios
3
+ module Util
4
+
5
+ module VersionUtil
6
+
7
+ # Compares two version designators and returns a spaceship comparison
8
+ # result
9
+ #
10
+ # === Signature
11
+ #
12
+ # * *Parameters:*
13
+ # - +lhs+ [String, Array[Integer|String]] The left-hand comparand
14
+ # - +rhs+ [String, Array[Integer|String]] The right-hand comparand
15
+ #
16
+ # * *Returns:*
17
+ # - 0 if the two version designators represent exactly the same version
18
+ # - <0 if the +lhs+ version designator represents an earlier version
19
+ # than the +rhs+ version designator
20
+ # - >0 if the +lhs+ version designator represents a later version
21
+ # than the +rhs+ version designator
22
+ def self.version_compare lhs, rhs
23
+
24
+ lhs = lhs.split('.') if String === lhs
25
+ rhs = rhs.split('.') if String === rhs
26
+
27
+ lhs = lhs.map { |n| n.to_i }
28
+ rhs = rhs.map { |n| n.to_i }
29
+
30
+ if lhs.size < rhs.size
31
+
32
+ lhs += [ 0 ] * (rhs.size - lhs.size)
33
+ else
34
+
35
+ rhs += [ 0 ] * (lhs.size - rhs.size)
36
+ end
37
+
38
+ lhs <=> rhs
39
+ end
40
+ end # module VersionUtil
41
+
42
+ end # module Util
43
+ end # module Pantheios
44
+
@@ -0,0 +1,69 @@
1
+
2
+ # ######################################################################## #
3
+ # File: lib/pantheios/version.rb
4
+ #
5
+ # Purpose: Version for Pantheios.Ruby library
6
+ #
7
+ # Created: 2nd April 2011
8
+ # Updated: 6th January 2018
9
+ #
10
+ # Home: http://github.com/synesissoftware/Pantheios-Ruby
11
+ #
12
+ # Author: Matthew Wilson
13
+ #
14
+ # Copyright (c) 2011-2018, Matthew Wilson and Synesis Software
15
+ # All rights reserved.
16
+ #
17
+ # Redistribution and use in source and binary forms, with or without
18
+ # modification, are permitted provided that the following conditions are
19
+ # met:
20
+ #
21
+ # * Redistributions of source code must retain the above copyright
22
+ # notice, this list of conditions and the following disclaimer.
23
+ #
24
+ # * Redistributions in binary form must reproduce the above copyright
25
+ # notice, this list of conditions and the following disclaimer in the
26
+ # documentation and/or other materials provided with the distribution.
27
+ #
28
+ # * Neither the names of the copyright holder nor the names of its
29
+ # contributors may be used to endorse or promote products derived from
30
+ # this software without specific prior written permission.
31
+ #
32
+ # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
33
+ # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
34
+ # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
35
+ # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
36
+ # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
37
+ # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
38
+ # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
39
+ # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
40
+ # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
41
+ # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
42
+ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43
+ #
44
+ # ######################################################################## #
45
+
46
+
47
+ =begin
48
+ =end
49
+
50
+ module Pantheios
51
+
52
+ # Current version of the Pantheios.Ruby library
53
+ VERSION = '0.9.6'
54
+
55
+ private
56
+ VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
57
+ public
58
+ # Major version of the Pantheios.Ruby library
59
+ VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
60
+ # Minor version of the Pantheios.Ruby library
61
+ VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
62
+ # Revision version of the Pantheios.Ruby library
63
+ VERSION_REVISION = VERSION_PARTS_[2] # :nodoc:
64
+
65
+ end # module Pantheios
66
+
67
+ # ############################## end of file ############################# #
68
+
69
+
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../..', 'lib')
4
+
5
+ require 'pantheios/application_layer/param_name_list'
6
+
7
+ require 'xqsr3/extensions/test/unit'
8
+
9
+ require 'test/unit'
10
+
11
+ class Test_ParamNameList_type_characteristics < Test::Unit::TestCase
12
+
13
+ include ::Pantheios::ApplicationLayer
14
+
15
+ def test_ParamNameList_type_exists
16
+
17
+ assert defined? ParamNameList
18
+ end
19
+
20
+ def test_ParamNames_type_exists
21
+
22
+ assert defined? ParamNames
23
+ end
24
+
25
+ def test_ParamNameList_type_is_a_class
26
+
27
+ assert ParamNameList.is_a? ::Class
28
+ end
29
+
30
+ def test_ParamNames_type_is_a_class
31
+
32
+ assert ParamNames.is_a? ::Class
33
+ end
34
+ end
35
+
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../..', 'lib')
4
+
5
+ require 'pantheios/application_layer/stock_severity_levels'
6
+
7
+ require 'xqsr3/extensions/test/unit'
8
+
9
+ require 'test/unit'
10
+
11
+ class Test_StockSeverityLevels < Test::Unit::TestCase
12
+
13
+ include ::Pantheios::ApplicationLayer
14
+
15
+ EXPECTED_LEVELS_PRIME = %w{
16
+
17
+ violation
18
+ alert
19
+ critical
20
+ failure
21
+ warning
22
+ notice
23
+ informational
24
+ debug0
25
+ debug1
26
+ debug2
27
+ debug3
28
+ debug4
29
+ trace
30
+ }.map { |s| s.to_sym }
31
+
32
+ EXPECTED_LEVELS = %w{
33
+
34
+ emergency
35
+ info
36
+ warn
37
+ }.map { |s| s.to_sym } + EXPECTED_LEVELS_PRIME
38
+
39
+ def test_StockSeverityLevels_type_exists
40
+
41
+ assert defined? StockSeverityLevels
42
+ end
43
+
44
+ def test_StockSeverityLevels_type_is_a_module
45
+
46
+ assert_kind_of(::Module, StockSeverityLevels) if defined?(StockSeverityLevels)
47
+ end
48
+
49
+ def test_StockSeverityLevels_has_constants
50
+
51
+ if defined? StockSeverityLevels
52
+
53
+ assert StockSeverityLevels.const_defined?(:STOCK_SEVERITY_LEVELS)
54
+ assert StockSeverityLevels.const_defined?(:STOCK_SEVERITY_LEVEL_VALUES)
55
+ assert StockSeverityLevels.const_defined?(:STOCK_SEVERITY_LEVEL_STRINGS)
56
+ end
57
+ end
58
+
59
+ def test_StockSeverityLevels_expected_levels
60
+
61
+ EXPECTED_LEVELS.each do |sev|
62
+
63
+ assert(StockSeverityLevels::STOCK_SEVERITY_LEVELS.include?(sev), "did not find level #{::Symbol === sev ? ':' : ''}#{sev} in #{StockSeverityLevels}::STOCK_SEVERITY_LEVELS")
64
+ end
65
+ end
66
+
67
+ def test_StockSeverityLevels_expected_prime_levels
68
+
69
+ EXPECTED_LEVELS_PRIME.each do |sev|
70
+
71
+ assert(StockSeverityLevels::STOCK_SEVERITY_LEVELS_PRIME.include?(sev), "did not find level #{::Symbol === sev ? ':' : ''}#{sev} in #{StockSeverityLevels}::STOCK_SEVERITY_LEVELS")
72
+ end
73
+ end
74
+
75
+ def test_StockSeverityLevels_expected_prime_levels_have_distinct_values
76
+
77
+ values = {}
78
+
79
+ EXPECTED_LEVELS_PRIME.each do |sev|
80
+
81
+ value = StockSeverityLevels::STOCK_SEVERITY_LEVEL_VALUES[sev]
82
+
83
+ assert(false, "value #{value} for severity '#{sev}' is not unique") if values.has_key?(value)
84
+
85
+ values[value] = value
86
+ end
87
+ end
88
+
89
+ def test_StockSeverityLevels_expected_prime_levels_have_distinct_strings
90
+
91
+ strings = {}
92
+
93
+ EXPECTED_LEVELS_PRIME.each do |sev|
94
+
95
+ string = StockSeverityLevels::STOCK_SEVERITY_LEVEL_STRINGS[sev]
96
+
97
+ assert(false, "string '#{string}' for severity '#{sev}' is not unique") if strings.has_key?(string)
98
+
99
+ strings[string] = string
100
+ end
101
+ end
102
+ end
103
+
@@ -0,0 +1,12 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # executes all other tests
4
+
5
+ this_dir = File.expand_path(File.dirname(__FILE__))
6
+
7
+ # all tc_*rb in current directory
8
+ Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
9
+
10
+ # all ts_*rb in immediate sub-directories
11
+ Dir[File.join(this_dir, '*', 'ts_*rb')].each { |file| require file }
12
+
@@ -0,0 +1,12 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # executes all other tests
4
+
5
+ this_dir = File.expand_path(File.dirname(__FILE__))
6
+
7
+ # all tc_*rb in current directory
8
+ Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
9
+
10
+ # all ts_*rb in immediate sub-directories
11
+ Dir[File.join(this_dir, '*', 'ts_*rb')].each { |file| require file }
12
+
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), '../../..', 'lib')
4
+
5
+ require 'pantheios/util/thread_util'
6
+
7
+ require 'xqsr3/extensions/test/unit'
8
+
9
+ require 'test/unit'
10
+
11
+ class Test_ThreadUtil_set_thread_name < Test::Unit::TestCase
12
+
13
+ TU = ::Pantheios::Util::ThreadUtil
14
+
15
+ def test_new_Thread_does_not_have_attribute
16
+
17
+ t = Thread.new {}
18
+
19
+ assert_not t.respond_to? :thread_name
20
+ end
21
+
22
+ def test_new_Thread_can_accept_attribute
23
+
24
+ t = Thread.new {}
25
+
26
+ assert_not t.respond_to? :thread_name
27
+
28
+ TU.set_thread_name t, ''
29
+
30
+ assert_true t.respond_to? :thread_name
31
+
32
+ assert_equal '', t.thread_name
33
+ end
34
+
35
+ def test_attribute_can_be_changed
36
+
37
+ t = Thread.new {}
38
+
39
+ TU.set_thread_name t, 'name-1'
40
+
41
+ assert_equal 'name-1', t.thread_name
42
+
43
+ TU.set_thread_name t, 'name-2'
44
+
45
+ assert_equal 'name-2', t.thread_name
46
+ end
47
+ end
48
+
49
+ class Test_parameter_checks_as_included_module < Test::Unit::TestCase
50
+
51
+ class NonThread1
52
+
53
+ include ::Pantheios::Util::ThreadUtil::ThreadName
54
+ end
55
+
56
+ class Thread1 < Thread
57
+
58
+ include ::Pantheios::Util::ThreadUtil::ThreadName
59
+
60
+ def initialize
61
+
62
+ super
63
+ end
64
+ end
65
+
66
+
67
+ def test_NonThread1_1
68
+
69
+ t = NonThread1.new
70
+
71
+ assert_equal Thread.current.to_s, t.thread_name
72
+ end
73
+
74
+ def test_NonThread1_2
75
+
76
+ t = NonThread1.new
77
+
78
+ t.thread_name = 'the-thread'
79
+
80
+ assert_equal 'the-thread', t.thread_name
81
+ end
82
+
83
+
84
+ def test_Thread1_1
85
+
86
+ t = Thread1.new {}
87
+
88
+ assert_equal t.to_s, t.thread_name
89
+ end
90
+
91
+ def test_Thread1_2
92
+
93
+ t = Thread1.new {}
94
+
95
+ t.thread_name = 'another-thread'
96
+
97
+ assert_equal 'another-thread', t.thread_name
98
+ end
99
+ end
100
+