Class: OMF::SFA::Resource::OGroup

Inherits:
OResource
  • Object
show all
Defined in:
lib/omf-sfa/resource/ogroup.rb

Overview

Groups contain other resources including other groups

Direct Known Subclasses

CompGroup, GroupComponent, OAccount

Instance Method Summary collapse

Methods inherited from OResource

#_dirty_self?, #_oprops_to_hash, #clone, #default_href_prefix, #destroy, #destroy!, #dirty_self?, #href, href_resolver, init, json_create, #oproperties_as_hash, #oproperty, oproperty, #oproperty_array_get, #oproperty_get, #oproperty_set, prop_all, #remove_from_all_groups, #status, #to_hash, #to_hash_brief, #to_json, #uuid

Instance Method Details

#add_members(member_a) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/omf-sfa/resource/ogroup.rb', line 49

def add_members(member_a)
  member_a.each do |r|
    unless member?(r)
      self.contains_resources << r
    end
  end
end

#all_resources(set = Set.new) ⇒ Object

Add this resource and all contained to set.



73
74
75
76
77
# File 'lib/omf-sfa/resource/ogroup.rb', line 73

def all_resources(set = Set.new)
  set << self
  self.each_resource { |r| r.all_resources(set) }
  set
end

#each_resource(&block) ⇒ Object



64
65
66
# File 'lib/omf-sfa/resource/ogroup.rb', line 64

def each_resource(&block)
  self.contains_resources().each &block
end

#empty_groupObject

Unlink all resources within this group.

Note: Maybe should trigger an event for those resources no longer belonging to any group



26
27
28
# File 'lib/omf-sfa/resource/ogroup.rb', line 26

def empty_group
  self.group_memberships.each {|m| m.destroy}
end

#group?Boolean

Return true if this resource is a Group

Returns:

  • (Boolean)


17
18
19
# File 'lib/omf-sfa/resource/ogroup.rb', line 17

def group?
  true
end

#member?(resource) ⇒ Boolean

Return true if resource is a DIRECT member of this group

Returns:

  • (Boolean)


59
60
61
62
# File 'lib/omf-sfa/resource/ogroup.rb', line 59

def member?(resource)
  # NOTE: most likely very inefficient
  self.group_memberships.first(:o_resource => resource) != nil
end

#membersObject



45
46
47
# File 'lib/omf-sfa/resource/ogroup.rb', line 45

def members
  self.contains_resources
end

#members=(member_a) ⇒ Object

Set membership to member_a. Removes any existing members which aren’t listed in member_a.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/omf-sfa/resource/ogroup.rb', line 33

def members=(member_a)
  ms = member_a.to_set
  self.group_memberships.each do |m|
    unless ms.delete?(m.o_resource)
      m.destroy # no longer member
    end
  end
  # add remaining, new members
  ms.each do |m| self.contains_resources << m end
  self.contains_resources
end

#resource_typeObject



68
69
70
# File 'lib/omf-sfa/resource/ogroup.rb', line 68

def resource_type
  'group'
end

#to_hash_long(h, objs, opts = {}) ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/omf-sfa/resource/ogroup.rb', line 79

def to_hash_long(h, objs, opts = {})
  super
  href_only = opts[:level] >= opts[:max_level]
  h[:resources] = self.contains_resources.map do |r|
    href_only ? r.href : r.to_hash(objs, opts)
  end
  h
end