Class: Eventsimple::Message
- Inherits:
-
Dry::Struct
- Object
- Dry::Struct
- Eventsimple::Message
- Defined in:
- lib/eventsimple/message.rb
Direct Known Subclasses
Class Method Summary collapse
- .attribute(name, type = Dry::Types::Any, **options) ⇒ Object
- .attribute?(name, type = Dry::Types::Any, **options) ⇒ Boolean
- .optional ⇒ Object
- .valid_eventsimple_type?(type) ⇒ Boolean
- .validate_type(type) ⇒ Object
Instance Method Summary collapse
Class Method Details
.attribute(name, type = Dry::Types::Any, **options) ⇒ Object
25 26 27 28 |
# File 'lib/eventsimple/message.rb', line 25 def self.attribute(name, type = Dry::Types::Any, **) validate_type(type) super end |
.attribute?(name, type = Dry::Types::Any, **options) ⇒ Boolean
30 31 32 33 |
# File 'lib/eventsimple/message.rb', line 30 def self.attribute?(name, type = Dry::Types::Any, **) validate_type(type) super end |
.optional ⇒ Object
36 37 38 |
# File 'lib/eventsimple/message.rb', line 36 def optional super.(Eventsimple::Types::EVENTSIMPLE_META) end |
.valid_eventsimple_type?(type) ⇒ Boolean
62 63 64 65 66 67 |
# File 'lib/eventsimple/message.rb', line 62 def valid_eventsimple_type?(type) return true if type.respond_to?(:meta) && type.[:eventsimple] == true return true if type.is_a?(Class) && type < Eventsimple::Message false end |
.validate_type(type) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/eventsimple/message.rb', line 40 def validate_type(type) return if valid_eventsimple_type?(type) source_location = begin source = const_source_location(name)&.first if respond_to?(:const_source_location) && name source || caller_locations.find { |loc| !loc.path.include?('eventsimple') }&.path rescue StandardError 'unknown' end = [ "Only Eventsimple::Types are allowed in Message attributes. \n", "File: #{source_location} \n", "Received: #{type.inspect} \n", "Use Eventsimple::Types::String, Eventsimple::Types::Integer, etc. \n", ].join(' ') deprecator = ActiveSupport::Deprecation.new deprecator.behavior = Rails.application.config.active_support.deprecation deprecator.warn() end |
Instance Method Details
#inspect ⇒ Object
21 22 23 |
# File 'lib/eventsimple/message.rb', line 21 def inspect as_json end |