Module: Plist::Emit

### Home Classes Methods

### In Files

- lib/facter/util/plist/generator.rb

### Methods

- ::dump
- ::save_plist
- #save_plist
- #to_plist

### Files

- LICENSE
- Rakefile
- THANKS

### Class/Module Index

Quicksearch

- Facter
- Facter::Application
- Facter::Manufacturer
- Facter::Memory
- Facter::NetMask
- Facter::Util
- Facter::Util::CFPropertyList
- Facter::Util::CFPropertyList::CFArray
- Facter::Util::CFPropertyList::CFBoolean
- Facter::Util::CFPropertyList::CFData
- Facter::Util::CFPropertyList::CFDate
- Facter::Util::CFPropertyList::CFDictionary
- Facter::Util::CFPropertyList::CFInteger
- Facter::Util::CFPropertyList::CFReal
- Facter::Util::CFPropertyList::CFString
- Facter::Util::CFPropertyList::CFType
- Facter::Util::CFPropertyList::XML
- Facter::Util::Collection
- Facter::Util::CompositeLoader
- Facter::Util::Config
- Facter::Util::Confine
- Facter::Util::DirectoryLoader
- Facter::Util::DirectoryLoader::NoSuchDirectoryError
- Facter::Util::EC2
- Facter::Util::Fact
- Facter::Util::FileRead
- Facter::Util::IP
- Facter::Util::IP::Windows
- Facter::Util::IP::Windows::Bindings4
- Facter::Util::IP::Windows::Bindings6
- Facter::Util::Loader
- Facter::Util::Macaddress
- Facter::Util::Macaddress::Darwin
- Facter::Util::Macaddress::Windows
- Facter::Util::Macosx
- Facter::Util::MonkeyPatches
- Facter::Util::MonkeyPatches::Lines
- Facter::Util::NothingLoader
- Facter::Util::Parser
- Facter::Util::Parser::Base
- Facter::Util::Parser::JsonParser
- Facter::Util::Parser::KeyValuePairOutputFormat
- Facter::Util::Parser::NothingParser
- Facter::Util::Parser::PowershellParser
- Facter::Util::Parser::ScriptParser
- Facter::Util::Parser::TextParser
- Facter::Util::Parser::YamlParser
- Facter::Util::Processor
- Facter::Util::Registry
- Facter::Util::Resolution
- Facter::Util::SolarisZones
- Facter::Util::Uptime
- Facter::Util::Values
- Facter::Util::Virtual
- Facter::Util::Vlans
- Facter::Util::WMI
- Facter::Util::Xendomains
- Plist
- Plist::Emit
- Plist::Listener
- Plist::PArray
- Plist::PData
- Plist::PDate
- Plist::PDict
- Plist::PFalse
- Plist::PInteger
- Plist::PKey
- Plist::PList
- Plist::PReal
- Plist::PString
- Plist::PTag
- Plist::PTrue
- Plist::StreamParser
- CFFormatError
- CFPlistError
- CFTypeError
- IO
- Object
- String

No matching classes.

# Plist::Emit

### Create a plist

You can dump an object to a plist in one of two ways:

- `Plist::Emit.dump(obj)`

- `obj.to_plist`

  - This requires that you mixin the `Plist::Emit` module, which is already done for `Array` and `Hash`.

The following Ruby classes are converted into native plist types:

    Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time, true, false

- `Array` and `Hash` are both recursive; their elements will be converted into plist nodes inside the <array> and <dict> containers (respectively).

- `IO` (and its descendants) and `StringIO` objects are read from and their contents placed in a <data> element.

- User classes may implement `to_plist_node` to dictate how they should be serialized; otherwise the object will be passed to `Marshal.dump` and the result placed in a <data> element.

For detailed usage instructions, refer to USAGE and the methods documented below.

### Public Class Methods

dump(obj, envelope = true) click to toggle source

The following Ruby classes are converted into native plist types:

    Array, Bignum, Date, DateTime, Fixnum, Float, Hash, Integer, String, Symbol, Time

Write us (via RubyForge) if you think another class can be coerced safely into one of the expected plist classes.

`IO` and `StringIO` objects are encoded and placed in <data> elements; other objects are `Marshal.dump`'ed unless they implement `to_plist_node`.

The `envelope` parameters dictates whether or not the resultant plist fragment is wrapped in the normal XML/plist header and footer. Set it to false if you only want the fragment.

    # File lib/facter/util/plist/generator.rb, line 43
    def self.dump(obj, envelope = true)
      output = plist_node(obj)

      output = wrap(output) if envelope

      return output
    end

save_plist(obj, filename) click to toggle source

Writes the serialized object's plist to the specified filename.

    # File lib/facter/util/plist/generator.rb, line 52
    def self.save_plist(obj, filename)
      File.open(filename, 'wb') do |f|
        f.write(obj.to_plist)
      end
    end

### Public Instance Methods

save_plist(filename) click to toggle source

Helper method for injecting into classes. Calls `Plist::Emit.save_plist` with `self`.

    # File lib/facter/util/plist/generator.rb, line 31
    def save_plist(filename)
      Plist::Emit.save_plist(self, filename)
    end

to_plist(envelope = true) click to toggle source

Helper method for injecting into classes. Calls `Plist::Emit.dump` with `self`.

    # File lib/facter/util/plist/generator.rb, line 26
    def to_plist(envelope = true)
      return Plist::Emit.dump(self, envelope)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.