Sha256: 662443d563ec190d86951914a88a04f02cd6a1180779fb8763818642061581f7

Contents?: true

Size: 1.01 KB

Versions: 39

Compression:

Stored size: 1.01 KB

Contents

module Inferno
  module Repositories
    class Messages < Repository
      def messages_for_result(result_id)
        self.class::Model
          .order(:index)
          .where(result_id: 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
          time = Time.now
          self.created_at ||= time
          self.updated_at ||= time
          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

39 entries across 39 versions & 1 rubygems

Version Path
inferno_core-0.3.12 lib/inferno/repositories/messages.rb
inferno_core-0.3.11 lib/inferno/repositories/messages.rb
inferno_core-0.3.10 lib/inferno/repositories/messages.rb
inferno_core-0.3.9 lib/inferno/repositories/messages.rb
inferno_core-0.3.8 lib/inferno/repositories/messages.rb
inferno_core-0.3.7 lib/inferno/repositories/messages.rb
inferno_core-0.3.6 lib/inferno/repositories/messages.rb
inferno_core-0.3.5 lib/inferno/repositories/messages.rb
inferno_core-0.3.4 lib/inferno/repositories/messages.rb
inferno_core-0.3.3 lib/inferno/repositories/messages.rb
inferno_core-0.3.2 lib/inferno/repositories/messages.rb
inferno_core-0.3.1 lib/inferno/repositories/messages.rb
inferno_core-0.3.0 lib/inferno/repositories/messages.rb
inferno_core-0.3.0.rc1 lib/inferno/repositories/messages.rb
inferno_core-0.2.0 lib/inferno/repositories/messages.rb
inferno_core-0.2.0.rc4 lib/inferno/repositories/messages.rb
inferno_core-0.2.0.rc3 lib/inferno/repositories/messages.rb
inferno_core-0.2.0.rc2 lib/inferno/repositories/messages.rb
inferno_core-0.2.0.rc1 lib/inferno/repositories/messages.rb
inferno_core-0.1.4.pre lib/inferno/repositories/messages.rb