Class: Salesforce::Metadata::PermissionSet

Inherits:
Object
  • Object
show all
Includes:
ROXML
Defined in:
lib/mdata/metadata/PermissionSet.rb

Overview

Author:

  • Ben Burwell

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#filenameObject

Returns the value of attribute filename.



15
16
17
# File 'lib/mdata/metadata/PermissionSet.rb', line 15

def filename
  @filename
end

Class Method Details

.read(name, dir) ⇒ PermissionSet

Read a permissionset file from its name and directory

The default file path is ‘./src/permissionsets/NAME.permissionset`, but the directory can be overridden by passing a non-nil String.

Parameters:

  • name (String)

    the name of the permissionset to read, like ‘Admin’

  • dir (String)

    the directory to search for the permissionset in. If nil, defaults to ‘./src/permissionsets`.

Returns:

  • (PermissionSet)

    the permissionset object that has been instantiated



75
76
77
78
79
80
81
# File 'lib/mdata/metadata/PermissionSet.rb', line 75

def self.read name, dir
	dir = './src/permissionsets' if dir.nil?
	filename = "#{dir}/#{name}.permissionset"
	permissionset = PermissionSet.from_xml(File.read(filename))
	permissionset.filename = filename
	permissionset
end

.touch(name, dir) ⇒ Object

Create an empty permissionset by name in directory

Parameters:

  • name (String)

    the name of the permissionset to create

  • dir (String)

    the directory to create it in, defaulting to ‘./src/permissionsets`.



100
101
102
103
104
105
106
# File 'lib/mdata/metadata/PermissionSet.rb', line 100

def self.touch name, dir
	dir = './src/permissionsets' if dir.nil?
	filename = "#{dir}/#{name}.permissionset"
	permissionset = PermissionSet.new
	permissionset.filename = filename
	permissionset.save
end

Instance Method Details

#saveObject

Save the permissionset to disk, writing it to the file from whence it came

Relies on the permissionset object having a ‘@filename` to save to.



86
87
88
89
90
91
92
93
# File 'lib/mdata/metadata/PermissionSet.rb', line 86

def save
	doc = ::Nokogiri::XML::Document.new
	doc.root = to_xml()
	doc.root.add_namespace nil, 'http://soap.sforce.com/2006/04/metadata'
	File.open @filename, 'w' do |file|
	file << doc.to_xml(:indent => 4, :encoding => 'UTF-8')
	end
end