Class: Pantheios::Core::Internals_::State
- Inherits:
-
Object
- Object
- Pantheios::Core::Internals_::State
- Defined in:
- lib/pantheios/core.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#back_end ⇒ Object
readonly
Returns the value of attribute back_end.
-
#front_end ⇒ Object
readonly
Returns the value of attribute front_end.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Instance Method Summary collapse
- #discriminator ⇒ Object
-
#initialize(default_fe, **options) ⇒ State
constructor
A new instance of State.
- #log ⇒ Object
- #requires_prefix? ⇒ Boolean
- #set_back_end(be) ⇒ Object
- #set_front_end(fe) ⇒ Object
- #set_service(svc) ⇒ Object
- #severity_logged?(severity) ⇒ Boolean
Constructor Details
#initialize(default_fe, **options) ⇒ State
93 94 95 96 97 98 99 100 |
# File 'lib/pantheios/core.rb', line 93 def initialize default_fe, ** @mx_service = Mutex.new @front_end = nil @back_end = nil @requires_prefix = false; @default_fe = default_fe end |
Instance Attribute Details
#back_end ⇒ Object (readonly)
Returns the value of attribute back_end.
197 198 199 |
# File 'lib/pantheios/core.rb', line 197 def back_end @back_end end |
#front_end ⇒ Object (readonly)
Returns the value of attribute front_end.
196 197 198 |
# File 'lib/pantheios/core.rb', line 196 def front_end @front_end end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
195 196 197 |
# File 'lib/pantheios/core.rb', line 195 def service @service end |
Instance Method Details
#discriminator ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/pantheios/core.rb', line 182 def discriminator @mx_service.synchronize do if @service && @service.respond_to?(:severity_logged?) return @service end @front_end end end |
#log ⇒ Object
178 179 180 |
# File 'lib/pantheios/core.rb', line 178 def log end |
#requires_prefix? ⇒ Boolean
198 |
# File 'lib/pantheios/core.rb', line 198 def requires_prefix?; @requires_prefix; end |
#set_back_end(be) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/pantheios/core.rb', line 120 def set_back_end be raise ::TypeError, "back-end instance (#{fe.class}) does not respond to all the required messages ([ #{Constants_::REQUIRED_BACKEND_METHODS.join(', ')} ])" unless be && Constants_::REQUIRED_BACKEND_METHODS.all? { |m| be.respond_to? m } r = nil srp = svc.respond_to?(:requires_prefix?) ? svc.requires_prefix? : true @mx_service.synchronize do r, @back_end, @requires_prefix = @back_end, be, srp end return r end |
#set_front_end(fe) ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/pantheios/core.rb', line 102 def set_front_end fe raise ::TypeError, "front-end instance (#{fe.class}) does not respond to all the required messages ([ #{Constants_::REQUIRED_FRONTEND_METHODS.join(', ')} ])" unless fe && Constants_::REQUIRED_FRONTEND_METHODS.all? { |m| fe.respond_to? m } r = nil fe ||= @default_fe @mx_service.synchronize do r, @front_end = @front_end, fe end r = nil if r.object_id == @default_fe.object_id return r end |
#set_service(svc) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/pantheios/core.rb', line 135 def set_service svc raise ::ArgumentError, 'service instance may not be nil' if svc.nil? raise ::TypeError, "service instance (#{svc.class}) does not respond to all the required messages ([ #{Constants_::REQUIRED_SERVICE_METHODS.join(', ')} ])" unless Constants_::REQUIRED_SERVICE_METHODS.all? { |m| svc.respond_to? m } nrcs = ::Pantheios::Util::ReflectionUtil.non_root_classes svc raise ::TypeError, "service instance class - #{svc.class} - inherits some of the required messages - [ #{Constants_::REQUIRED_SERVICE_METHODS.join(', ')} ] - from the top-level" unless Constants_::REQUIRED_SERVICE_METHODS.all? { |m| nrcs.any? { |nr| nr.instance_methods(false).include? m } } r = [] srp = svc.respond_to?(:requires_prefix?) ? svc.requires_prefix? : true @mx_service.synchronize do r << @front_end r << @back_end @front_end, @back_end, @requires_prefix = svc, svc, srp end return r end |
#severity_logged?(severity) ⇒ Boolean
161 162 163 164 165 166 167 168 169 |
# File 'lib/pantheios/core.rb', line 161 def severity_logged? severity @mx_service.synchronize do return nil unless @front_end @front_end.severity_logged? severity end end |