Class: Adsedare::AppGroupsCapability

Inherits:
Capability show all
Defined in:
lib/adsedare/capabilities.rb

Instance Attribute Summary collapse

Attributes inherited from Capability

#type

Instance Method Summary collapse

Constructor Details

#initialize(type, groups) ⇒ AppGroupsCapability

Returns a new instance of AppGroupsCapability.



94
95
96
97
# File 'lib/adsedare/capabilities.rb', line 94

def initialize(type, groups)
  super(type)
  @groups = groups
end

Instance Attribute Details

#groupsObject (readonly)

Returns the value of attribute groups.



92
93
94
# File 'lib/adsedare/capabilities.rb', line 92

def groups
  @groups
end

Instance Method Details

#check?(bundle_info) ⇒ Boolean

Returns:

  • (Boolean)


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/adsedare/capabilities.rb', line 99

def check?(bundle_info)
  have_capability = bundle_info["included"].any? {
    |cap|
    cap["type"] == "capabilities" && cap["id"] == @type
  }
  return false unless have_capability

  registered_groups = bundle_info["included"].select {
    |cap|
    cap["type"] == "appGroups"
  }.map {
    |cap|
    cap["attributes"]["identifier"]
  }

  return @groups.all? { |group| registered_groups.include?(group) }
end

#to_bundle_capability(bundle_info, team_id) ⇒ Object



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/adsedare/capabilities.rb', line 117

def to_bundle_capability(bundle_info, team_id)
  registered_app_groups = {}

  Starship::Client.get_app_groups(team_id).each {
    |app_group|
    registered_app_groups[app_group["identifier"]] = app_group["applicationGroup"]
  }

  @groups.each do |group|
    if not registered_app_groups.include?(group)
      new_app_group = Starship::Client.create_app_group(group, team_id)
      registered_app_groups[new_app_group["identifier"]] = new_app_group["applicationGroup"]
    end
  end

  bundle_capability = super(bundle_info, team_id)

  app_groups = {
    "data" => @groups.map { |group| { "type" => "appGroups", "id" => registered_app_groups[group] } },
  }

  bundle_capability["relationships"]["appGroups"] = app_groups

  return bundle_capability
end