Sha256: f660c1ae2e2e46803a314e9161b0642f3f79774296e73e0471b9dfbf54269e4a

Contents?: true

Size: 931 Bytes

Versions: 48

Compression:

Stored size: 931 Bytes

Contents

module Inferno
  module Repositories
    class Messages < Repository
      def messages_for_result(result_id)
        self.class::Model
          .order(:index)
          .where(result_id:)
          .to_a
          .map!(&:to_json_data)
          .each(&:deep_symbolize_keys!)
          .map! { |result| build_entity(result) }
      end

      class Model < Sequel::Model(db)
        many_to_one :result, class: 'Inferno::Repositories::Results::Model', key: :result_id

        def before_create
          self.id = SecureRandom.uuid
          super
        end

        def validate
          super
          types = Entities::Message::TYPES
          errors.add(:message, 'must be present') if message.blank?
          errors.add(:type, 'must be present') if type.blank?
          errors.add(:type, "'#{type}' is invalid. Must be one of: #{types.join(', ')}") unless types.include?(type)
        end
      end
    end
  end
end

Version data entries

48 entries across 48 versions & 1 rubygems

Version Path
inferno_core-0.6.1 lib/inferno/repositories/messages.rb
inferno_core-0.6.0 lib/inferno/repositories/messages.rb
inferno_core-0.5.4 lib/inferno/repositories/messages.rb
inferno_core-0.5.3 lib/inferno/repositories/messages.rb
inferno_core-0.5.2 lib/inferno/repositories/messages.rb
inferno_core-0.5.1 lib/inferno/repositories/messages.rb
inferno_core-0.5.0 lib/inferno/repositories/messages.rb
inferno_core-0.4.44 lib/inferno/repositories/messages.rb
inferno_core-0.4.43 lib/inferno/repositories/messages.rb
inferno_core-0.4.42 lib/inferno/repositories/messages.rb
inferno_core-0.4.41 lib/inferno/repositories/messages.rb
inferno_core-0.4.40 lib/inferno/repositories/messages.rb
inferno_core-0.4.39 lib/inferno/repositories/messages.rb
inferno_core-0.4.38 lib/inferno/repositories/messages.rb
inferno_core-0.4.35 lib/inferno/repositories/messages.rb
inferno_core-0.4.34 lib/inferno/repositories/messages.rb
inferno_core-0.4.33 lib/inferno/repositories/messages.rb
inferno_core-0.4.32 lib/inferno/repositories/messages.rb
inferno_core-0.4.31 lib/inferno/repositories/messages.rb
inferno_core-0.4.30 lib/inferno/repositories/messages.rb