Module: Kernel

Defined in:
lib/hotcocoa/core_extensions/kernel.rb

Overview

HotCocoa extensions for the Kernel module

Constant Summary collapse

PLIST_FORMATS =

A mapping, lol

Returns:

  • (Hash)
{
  xml:    NSPropertyListXMLFormat_v1_0,
  binary: NSPropertyListBinaryFormat_v1_0
}

Instance Method Summary collapse

Instance Method Details

#default_frameworkObject



11
# File 'lib/hotcocoa/core_extensions/kernel.rb', line 11

alias_method :default_framework, :framework

#framework(name) ⇒ Object

Override MacRuby’s built-in #framework method in order to support lazy loading frameworks inside of HotCocoa.



15
16
17
18
19
20
21
22
23
# File 'lib/hotcocoa/core_extensions/kernel.rb', line 15

def framework name
  if default_framework name
    $LOADED_FRAMEWORKS << name
    HotCocoa::Mappings.load name
    true
  else
    false
  end
end

#to_plist(format = :xml) ⇒ String

TODO:

encoding format can be pushed upstream?

Override MacRuby’s built-in #to_plist method to support specifying an output format. See PLIST_FORMATS for the available formats.

Examples:

Encoding a plist in the binary format

{ key: 'value' }.to_plist(:binary)

Returns:

  • (String)

    returns a string with the caller’s contents serialized as a plist and encoded using format

Raises:

  • (ArgumentError)


56
57
58
59
60
61
62
63
64
65
# File 'lib/hotcocoa/core_extensions/kernel.rb', line 56

def to_plist format = :xml
  format_const = PLIST_FORMATS[format]
  raise ArgumentError, "invalid format `#{format}'" unless format_const

  error = Pointer.new :id
  data  = NSPropertyListSerialization.dataFromPropertyList self,
                                                   format: format_const,
                                         errorDescription: error
  error[0] ? raise(Exception, error[0]) : data.to_str
end