Class: Cts::Mpx::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/cts/mpx/aci/extensions/cts/mpx/entry.rb

Overview

extensions to the Cts::Mpx::Entry

Instance Method Summary collapse

Instance Method Details

#dependenciesArray

Collection of dependencies required to deploy this entry

Returns:

  • (Array)

    unordered list of dependencies



8
9
10
11
12
13
14
15
16
17
# File 'lib/cts/mpx/aci/extensions/cts/mpx/entry.rb', line 8

def dependencies
  dependencies = []
  Cts::Mpx::Aci::Transformations.traverse_for(to_h[:entry], :transform) do |_k, v|
    next if v.start_with? "http://access.auth.theplatform.com/data/Account"
    next if v == "urn:cts:aci:target-account"

    dependencies.push v
  end
  dependencies.uniq
end

#diff(other_entry) ⇒ Object

return the difference between two entries

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
# File 'lib/cts/mpx/aci/extensions/cts/mpx/entry.rb', line 20

def diff(other_entry)
  raise ArgumentError, 'an entry must be supplied' unless other_entry.class == self.class
  raise ArgumentError, 'both entries must have the same service' unless service == other_entry.service
  raise ArgumentError, 'both entries must have the same endpoint' unless endpoint == other_entry.endpoint

  Diffy::Diff.new(to_s, other_entry.to_s).to_s
end

#directoryString

Returns computed path of the entry.

Returns:

  • (String)

    computed path of the entry.



36
37
38
# File 'lib/cts/mpx/aci/extensions/cts/mpx/entry.rb', line 36

def directory
  "#{service}/#{endpoint}"
end

#exists_by?(user, query) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


40
41
42
43
44
45
46
47
48
# File 'lib/cts/mpx/aci/extensions/cts/mpx/entry.rb', line 40

def exists_by?(user, query)
  raise ArgumentError, "user must be signed in" unless user&.token
  raise ArgumentError, "query must be a type of Query" unless query.is_a? Query

  query.run(user: user)
  return true if query.page.entries&.count&.positive?

  false
end

#filenameString

Returns computed filename of the entry.

Returns:

  • (String)

    computed filename of the entry.



29
30
31
32
33
# File 'lib/cts/mpx/aci/extensions/cts/mpx/entry.rb', line 29

def filename
  raise 'Entry must include a guid field' unless fields.collection.map(&:name).include? 'guid'

  "#{fields['guid']}.json"
end

#filepathString

Returns complete filepath for an entry.

Returns:

  • (String)

    complete filepath for an entry



51
52
53
# File 'lib/cts/mpx/aci/extensions/cts/mpx/entry.rb', line 51

def filepath
  "#{directory}/#{filename}"
end

#hashString

Returns MD5 hash, based on formatted JSON.

Returns:

  • (String)

    MD5 hash, based on formatted JSON



56
57
58
# File 'lib/cts/mpx/aci/extensions/cts/mpx/entry.rb', line 56

def hash
  Digest::MD5.hexdigest to_s
end

#includes_reference?Boolean

true if any reference is found in the entry, false otherwise.

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
# File 'lib/cts/mpx/aci/extensions/cts/mpx/entry.rb', line 63

def includes_reference?
  included = false
  Cts::Mpx::Aci::Transformations.traverse_for(to_h[:entry], :transform) do |_k, v|
    included = true
    v
  end
  included
end

#includes_transformed_reference?Boolean

true if any transformed reference is found in the entry, false otherwise.

Returns:

  • (Boolean)


75
76
77
78
79
80
81
82
83
# File 'lib/cts/mpx/aci/extensions/cts/mpx/entry.rb', line 75

def includes_transformed_reference?
  ref = false

  Cts::Mpx::Aci::Transformations.traverse_for(to_h[:entry], :untransform) do |_k, v|
    ref = true
    v
  end
  ref
end

#transform(user) ⇒ Object

transform all references in this entry

Raises:

  • (RuntimeError)

    if guid field is not included

  • (RuntimeError)

    if ownerId field is not included

  • (RuntimeError)

    if user is not set



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/cts/mpx/aci/extensions/cts/mpx/entry.rb', line 89

def transform(user)
  raise_entry_exceptions!(user)
  hash = to_h[:entry]
  output = Cts::Mpx::Aci::Transformations.traverse_for(hash, :transform) do |_k, v|
    if Cts::Mpx::Aci::Validators.field_reference? v
      Cts::Mpx::Aci::Transformations.transform_field_reference field_reference: v, user: user
    else
      Cts::Mpx::Aci::Transformations.transform_reference reference: v, user: user, original_account: fields['ownerId']
    end
  end
  @fields = Fields.create_from_data(data: output, xmlns: to_h[:namespace])
  self
end

#untransform(user, target_account) ⇒ Object

untransform all transformed references in this entry

Raises:

  • (RuntimeError)

    if guid field is not included

  • (RuntimeError)

    if ownerId field is not included

  • (RuntimeError)

    if user is not set



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/cts/mpx/aci/extensions/cts/mpx/entry.rb', line 107

def untransform(user, )
  raise_entry_exceptions!(user)
  hash = to_h[:entry]
  output = Cts::Mpx::Aci::Transformations.traverse_for(hash, :untransform) do |_k, v|
    if Cts::Mpx::Aci::Validators.transformed_field_reference? v
      Cts::Mpx::Aci::Transformations.untransform_field_reference transformed_reference: v, user: user
    else
      Cts::Mpx::Aci::Transformations.untransform_reference transformed_reference: v, user: user, target_account: 
    end
  end
  @fields = Fields.create_from_data(data: output, xmlns: to_h[:namespace])
  self
end