Module: CFoundryHelper::Helpers::SpaceHelper
- Defined in:
- lib/cfoundry_helper/helpers/space_helper.rb
Class Method Summary collapse
-
.add_roles(space, user, roles) ⇒ Object
takes an array of roles and adds the given user to the according space’s role lists throws an exception if any of the given arguments is nil or empty throws an exception if the given user is not registered with the space’s organization returns the space.
-
.create_space(org, spacename) ⇒ Object
creates a space with the given name within the given organization throws an exception if the given spacename is nil or empty throws an exception if the given organization is nil throws an exception if a space with the given name already exists within the given organization.
-
.delete_space(space) ⇒ Object
deletes a space throws an exception if the given space is nil throws an exception if the given space is not empty returns true on deletion.
-
.delete_space_recursive(space) ⇒ Object
deletes a given space recursively (all apps, services, .…) returns true if the space was deleted.
-
.exists?(org, spacename) ⇒ Boolean
returns true if a space with the given name exists within the given organization returns false if no space with the given name exists within the given organization.
- .exists_by_name?(org_name, space_name) ⇒ Boolean
-
.get_space(org, spacename) ⇒ Object
returns the given the space with the given name within the given organization returns nil of no space has been found.
-
.get_space_by_name(org_name, space_name) ⇒ Object
returns the space with the given name in the organization with the given name returns nil if no space has been found.
-
.is_empty?(space) ⇒ Boolean
returns true if no apps, service_instances, routes,.
-
.remove_roles(space, user, roles) ⇒ Object
takes an array of roles and removes the given user from the according space role lists throws an exception if any of the given arguments is nil or empty returns the space.
Class Method Details
.add_roles(space, user, roles) ⇒ Object
takes an array of roles and adds the given user to the according space’s role lists throws an exception if any of the given arguments is nil or empty throws an exception if the given user is not registered with the space’s organization returns the space
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/cfoundry_helper/helpers/space_helper.rb', line 79 def self.add_roles(space, user, roles) raise "No roles given!" if roles.nil? || roles.empty? raise "The given space is nil!" if space.nil? raise "The given user is nil!" if user.nil? roles.each do |r| if r == CFoundryHelper::Models::SpaceRole::MANAGER space.add_manager user elsif r == CFoundryHelper::Models::SpaceRole::AUDITOR space.add_auditor user elsif r == CFoundryHelper::Models::SpaceRole::DEVELOPER space.add_developer user end end space.update! space end |
.create_space(org, spacename) ⇒ Object
creates a space with the given name within the given organization throws an exception if the given spacename is nil or empty throws an exception if the given organization is nil throws an exception if a space with the given name already exists within the given organization
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/cfoundry_helper/helpers/space_helper.rb', line 8 def self.create_space(org, spacename) raise "The given organization is nil!" if org.nil? raise "The given spacename is nil!" if spacename.nil? raise "The given spacename is empty!" if spacename.eql?('') raise "The #{spacename} space already exists within #{org.name}!" if self.exists?(org, spacename) space = self.cc_client.space space.name = spacename space.organization = org space.create! space end |
.delete_space(space) ⇒ Object
deletes a space throws an exception if the given space is nil throws an exception if the given space is not empty returns true on deletion
25 26 27 28 29 30 31 32 |
# File 'lib/cfoundry_helper/helpers/space_helper.rb', line 25 def self.delete_space(space) raise "The given space is nil!" if space.nil? unless is_empty? space raise "The given space is not empty!" end space.delete! return true end |
.delete_space_recursive(space) ⇒ Object
deletes a given space recursively (all apps, services, .…) returns true if the space was deleted
36 37 38 39 |
# File 'lib/cfoundry_helper/helpers/space_helper.rb', line 36 def self.delete_space_recursive(space) raise "The given space is nil!" if space.nil? space.delete!(:recursive => true) end |
.exists?(org, spacename) ⇒ Boolean
returns true if a space with the given name exists within the given organization returns false if no space with the given name exists within the given organization
67 68 69 |
# File 'lib/cfoundry_helper/helpers/space_helper.rb', line 67 def self.exists?(org, spacename) return !org.space_by_name(spacename).nil? end |
.exists_by_name?(org_name, space_name) ⇒ Boolean
71 72 73 |
# File 'lib/cfoundry_helper/helpers/space_helper.rb', line 71 def self.exists_by_name?(org_name, space_name) return !self.get_space_by_name(org_name, space_name).nil? end |
.get_space(org, spacename) ⇒ Object
returns the given the space with the given name within the given organization returns nil of no space has been found
53 54 55 |
# File 'lib/cfoundry_helper/helpers/space_helper.rb', line 53 def self.get_space(org, spacename) org.space_by_name spacename end |
.get_space_by_name(org_name, space_name) ⇒ Object
returns the space with the given name in the organization with the given name returns nil if no space has been found
59 60 61 62 63 |
# File 'lib/cfoundry_helper/helpers/space_helper.rb', line 59 def self.get_space_by_name(org_name, space_name) org = CFoundryHelper::Helpers::OrganizationHelper.get_organization_by_name org_name return nil if org.nil? return self.get_space(org, space_name) end |
.is_empty?(space) ⇒ Boolean
returns true if no apps, service_instances, routes,
42 43 44 45 46 47 48 49 |
# File 'lib/cfoundry_helper/helpers/space_helper.rb', line 42 def self.is_empty?(space) return true if space.nil? if space.apps.count > 0 || space.service_instances.count > 0 || space.domains.count > 0 return false else return true end end |
.remove_roles(space, user, roles) ⇒ Object
takes an array of roles and removes the given user from the according space role lists throws an exception if any of the given arguments is nil or empty returns the space
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/cfoundry_helper/helpers/space_helper.rb', line 100 def self.remove_roles(space, user, roles) raise "No roles given!" if roles.nil? || roles.empty? raise "The given space is nil!" if space.nil? raise "The given user is nil!" if user.nil? roles.each do |r| if r == CFoundryHelper::Models::SpaceRole::MANAGER space.remove_manager user elsif r == CFoundryHelper::Models::SpaceRole::AUDITOR space.remove_auditor user elsif r == CFoundryHelper::Models::SpaceRole::DEVELOPER space.remove_developer user end end space.update! space end |