Class: Preneeds::Attachment

Inherits:
Object
  • Object
show all
Defined in:
app/models/preneeds/attachment.rb

Overview

Models a BurialForm form attachment

Constant Summary collapse

VETS_GOV =

string to populate #sending_source

'vets.gov'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Attachment

Creates a new instance of Preneeds::Attachment

Parameters:

  • args (Hash)

    hash with keys that correspond to attributes



35
36
37
38
# File 'app/models/preneeds/attachment.rb', line 35

def initialize(*args)
  super
  @data_handler = SecureRandom.hex
end

Instance Attribute Details

#attachment_typePreneeds::AttachmentType

Returns Preneeds::AttachmentType object.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/preneeds/attachment.rb', line 17

class Attachment
  include Virtus.model

  # string to populate #sending_source
  #
  VETS_GOV = 'vets.gov'

  attribute :attachment_type, Preneeds::AttachmentType
  attribute :sending_source, String, default: VETS_GOV
  attribute :file, (Rails.env.production? ? CarrierWave::Storage::AWSFile : CarrierWave::SanitizedFile)
  attribute :name, String

  attr_reader :data_handler

  # Creates a new instance of {Preneeds::Attachment}
  #
  # @param args [Hash] hash with keys that correspond to attributes
  #
  def initialize(*args)
    super
    @data_handler = SecureRandom.hex
  end

  # (see Preneeds::BurialForm#as_eoas)
  #
  def as_eoas
    {
      attachmentType: {
        attachmentTypeId: attachment_type.attachment_type_id
      },
      dataHandler: {
        'inc:Include': '',
        attributes!: {
          'inc:Include': {
            href: "cid:#{@data_handler}",
            'xmlns:inc': 'http://www.w3.org/2004/08/xop/include'
          }
        }
      },
      description: name,
      sendingName: VETS_GOV,
      sendingSource: sending_source
    }
  end
end

#data_handlerString

Returns auto-generated attachment id.

Returns:

  • (String)

    auto-generated attachment id



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/preneeds/attachment.rb', line 17

class Attachment
  include Virtus.model

  # string to populate #sending_source
  #
  VETS_GOV = 'vets.gov'

  attribute :attachment_type, Preneeds::AttachmentType
  attribute :sending_source, String, default: VETS_GOV
  attribute :file, (Rails.env.production? ? CarrierWave::Storage::AWSFile : CarrierWave::SanitizedFile)
  attribute :name, String

  attr_reader :data_handler

  # Creates a new instance of {Preneeds::Attachment}
  #
  # @param args [Hash] hash with keys that correspond to attributes
  #
  def initialize(*args)
    super
    @data_handler = SecureRandom.hex
  end

  # (see Preneeds::BurialForm#as_eoas)
  #
  def as_eoas
    {
      attachmentType: {
        attachmentTypeId: attachment_type.attachment_type_id
      },
      dataHandler: {
        'inc:Include': '',
        attributes!: {
          'inc:Include': {
            href: "cid:#{@data_handler}",
            'xmlns:inc': 'http://www.w3.org/2004/08/xop/include'
          }
        }
      },
      description: name,
      sendingName: VETS_GOV,
      sendingSource: sending_source
    }
  end
end

#fileCarrierWave::Storage::AWSFile, CarrierWave::SanitizedFile

Returns:

  • (CarrierWave::Storage::AWSFile, CarrierWave::SanitizedFile)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/preneeds/attachment.rb', line 17

class Attachment
  include Virtus.model

  # string to populate #sending_source
  #
  VETS_GOV = 'vets.gov'

  attribute :attachment_type, Preneeds::AttachmentType
  attribute :sending_source, String, default: VETS_GOV
  attribute :file, (Rails.env.production? ? CarrierWave::Storage::AWSFile : CarrierWave::SanitizedFile)
  attribute :name, String

  attr_reader :data_handler

  # Creates a new instance of {Preneeds::Attachment}
  #
  # @param args [Hash] hash with keys that correspond to attributes
  #
  def initialize(*args)
    super
    @data_handler = SecureRandom.hex
  end

  # (see Preneeds::BurialForm#as_eoas)
  #
  def as_eoas
    {
      attachmentType: {
        attachmentTypeId: attachment_type.attachment_type_id
      },
      dataHandler: {
        'inc:Include': '',
        attributes!: {
          'inc:Include': {
            href: "cid:#{@data_handler}",
            'xmlns:inc': 'http://www.w3.org/2004/08/xop/include'
          }
        }
      },
      description: name,
      sendingName: VETS_GOV,
      sendingSource: sending_source
    }
  end
end

#nameString

Returns attachment name.

Returns:

  • (String)

    attachment name



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/preneeds/attachment.rb', line 17

class Attachment
  include Virtus.model

  # string to populate #sending_source
  #
  VETS_GOV = 'vets.gov'

  attribute :attachment_type, Preneeds::AttachmentType
  attribute :sending_source, String, default: VETS_GOV
  attribute :file, (Rails.env.production? ? CarrierWave::Storage::AWSFile : CarrierWave::SanitizedFile)
  attribute :name, String

  attr_reader :data_handler

  # Creates a new instance of {Preneeds::Attachment}
  #
  # @param args [Hash] hash with keys that correspond to attributes
  #
  def initialize(*args)
    super
    @data_handler = SecureRandom.hex
  end

  # (see Preneeds::BurialForm#as_eoas)
  #
  def as_eoas
    {
      attachmentType: {
        attachmentTypeId: attachment_type.attachment_type_id
      },
      dataHandler: {
        'inc:Include': '',
        attributes!: {
          'inc:Include': {
            href: "cid:#{@data_handler}",
            'xmlns:inc': 'http://www.w3.org/2004/08/xop/include'
          }
        }
      },
      description: name,
      sendingName: VETS_GOV,
      sendingSource: sending_source
    }
  end
end

#sending_sourceString

Returns sending source; currently hard coded.

Returns:

  • (String)

    sending source; currently hard coded



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/preneeds/attachment.rb', line 17

class Attachment
  include Virtus.model

  # string to populate #sending_source
  #
  VETS_GOV = 'vets.gov'

  attribute :attachment_type, Preneeds::AttachmentType
  attribute :sending_source, String, default: VETS_GOV
  attribute :file, (Rails.env.production? ? CarrierWave::Storage::AWSFile : CarrierWave::SanitizedFile)
  attribute :name, String

  attr_reader :data_handler

  # Creates a new instance of {Preneeds::Attachment}
  #
  # @param args [Hash] hash with keys that correspond to attributes
  #
  def initialize(*args)
    super
    @data_handler = SecureRandom.hex
  end

  # (see Preneeds::BurialForm#as_eoas)
  #
  def as_eoas
    {
      attachmentType: {
        attachmentTypeId: attachment_type.attachment_type_id
      },
      dataHandler: {
        'inc:Include': '',
        attributes!: {
          'inc:Include': {
            href: "cid:#{@data_handler}",
            'xmlns:inc': 'http://www.w3.org/2004/08/xop/include'
          }
        }
      },
      description: name,
      sendingName: VETS_GOV,
      sendingSource: sending_source
    }
  end
end

Instance Method Details

#as_eoasHash

Converts object attributes to a hash to be used when constructing a SOAP request body. Hash attributes must correspond to XSD ordering or API call will fail

Returns:

  • (Hash)

    object attributes and association objects converted to EOAS service compatible hash



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/models/preneeds/attachment.rb', line 42

def as_eoas
  {
    attachmentType: {
      attachmentTypeId: attachment_type.attachment_type_id
    },
    dataHandler: {
      'inc:Include': '',
      attributes!: {
        'inc:Include': {
          href: "cid:#{@data_handler}",
          'xmlns:inc': 'http://www.w3.org/2004/08/xop/include'
        }
      }
    },
    description: name,
    sendingName: VETS_GOV,
    sendingSource: sending_source
  }
end