Module: Messaging::Handle::Build
- Defined in:
- lib/messaging/handle.rb
Constant Summary collapse
- Error =
Class.new(RuntimeError)
Class Method Summary collapse
- .configure?(instance, parameter_name) ⇒ Boolean
- .handler_logger ⇒ Object
- .send_session?(session, instance) ⇒ Boolean
- .send_settings?(settings, instance) ⇒ Boolean
Instance Method Summary collapse
Class Method Details
.configure?(instance, parameter_name) ⇒ Boolean
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/messaging/handle.rb', line 57 def self.configure?(instance, parameter_name) configure_method = instance.method(:configure) parameter_type, _ = configure_method.parameters.find do |type, name| name == parameter_name end return false if parameter_type.nil? return true if [:key, :keyreq].include?(parameter_type) = "Incorrect definition of handler's configure method. The #{parameter_name} parameter must be a keyword argument (Handler: #{instance.class}, Parameter Type: #{parameter_type.inspect})" handler_logger.error(tag: :handle) { } raise Error, end |
.handler_logger ⇒ Object
73 74 75 |
# File 'lib/messaging/handle.rb', line 73 def self.handler_logger @handler_logger ||= Log.get(self) end |
.send_session?(session, instance) ⇒ Boolean
49 50 51 |
# File 'lib/messaging/handle.rb', line 49 def self.send_session?(session, instance) configure?(instance, :session) && !session.nil? end |
.send_settings?(settings, instance) ⇒ Boolean
53 54 55 |
# File 'lib/messaging/handle.rb', line 53 def self.send_settings?(settings, instance) configure?(instance, :settings) && !settings.nil? end |
Instance Method Details
#build(strict: nil, session: nil, settings: nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/messaging/handle.rb', line 30 def build(strict: nil, session: nil, settings: nil) instance = new instance.strict = strict arguments = {} if Build.send_session?(session, instance) arguments[:session] = session end if Build.send_settings?(settings, instance) arguments[:settings] = settings end instance.configure(**arguments) instance end |