Class: Salesforce::Metadata::Profile

Inherits:
Object
  • Object
show all
Includes:
ROXML
Defined in:
lib/mdata/metadata/Profile.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/Profile.rb', line 15

def filename
  @filename
end

Class Method Details

.read(name, dir) ⇒ Profile

Read a profile file from its name and directory

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

Parameters:

  • name (String)

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

  • dir (String)

    the directory to search for the profile in. If nil, defaults to ‘./src/profiles`.

Returns:

  • (Profile)

    the profile object that has been instantiated



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

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

.touch(name, dir) ⇒ Object

Create an empty profile by name in directory

Parameters:

  • name (String)

    the name of the profile to create

  • dir (String)

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



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

def self.touch name, dir
	dir = './src/profiles' if dir.nil?
	filename = "#{dir}/#{name}.profile"
	profile = Profile.new
	profile.filename = filename
	profile.save
end

Instance Method Details

#saveObject

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

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



86
87
88
89
90
91
92
93
# File 'lib/mdata/metadata/Profile.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