Class List Method List File List

# Module: OSX::BundleSupport

Defined in:
  src/objc/mdl_bundle_support.m,
  src/ruby/osx/objc/oc_bundle_support.rb,
  src/objc/mdl_bundle_support.m

## Overview

Utilities for handling NSBundle stack in applications.

bundle_stack - stack for the current bundle and related parameter. the related parameter (additional_param) can be passed from RBApplicationInit() or RBBundleInit().

Examples:

    _push_bundle([bundle, additional_param])
    _pop_bundle     => [bundle, additional_param] or nil
    _current_bundle => [bundle, additional_param] or nil

## Defined Under Namespace

Classes: Logger

## Class Method Summary (collapse)

- + (OSX::NSMutableDictionary) _bundle_map

  Returns a dictionary contains Objective-C Class -> NSBundle relations.

- + (Array<OSX::NSBundle, Object>) _current_bundle

  Returns the current bundle in bundle stack.

- + (Array<OSX::NSBundle, Object>?) bind_class_with_current_bundle

  Binds a given Objective-C class to current bundle.

- + (OSX::NSBundle) bundle_for_class

  Returns an instalce of OSX::NSBundle that is main bundle of a given Objective-C class.

- + (Object) init_for_bundle(option = nil)

  Initializes RubyCocoa bundle from Cocoa applications.

## Class Method Details

### + (`OSX::NSMutableDictionary`) _bundle_map

Returns a dictionary contains Objective-C Class -> NSBundle relations.

Returns:

- (`OSX::NSMutableDictionary`)

    90

    # File 'src/objc/mdl_bundle_support.m', line 90

    static VALUE rb_bundle_map(VALUE mdl) { return ocid_to_rbobj(Qnil, gBundleMap); }

### + (`Array<OSX::NSBundle, Object>`) _current_bundle

Returns the current bundle in bundle stack.

Returns:

- (`Array<OSX::NSBundle, Object>`)

    85

    # File 'src/objc/mdl_bundle_support.m', line 85

    static VALUE rb_current_bundle(VALUE mdl) { return _current_bundle(); }

### + (`Array<OSX::NSBundle, Object>`?) bind_class_with_current_bundle

Binds a given Objective-C class to current bundle.

Parameters:

- objc_class (`Class`)

Returns:

- (`Array<OSX::NSBundle, Object>`)
- (`nil`) —

  if the bundle stack is empty.

    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139

    # File 'src/objc/mdl_bundle_support.m', line 127

    static VALUE
    rb_bind_class_with_current_bundle(VALUE mdl, VALUE objc_class)
    {
      VALUE stack_item;
      stack_item = _current_bundle();
      if (! NIL_P(stack_item)) {
        VALUE bundle = rb_ary_entry(stack_item, 0); // [bundle, additional_param] => bundle
        if (!gBundleMap) gBundleMap = [NSMutableDictionary new];
        [gBundleMap setObject:_ruby2ocid(bundle) forKey:_ruby2ocid(objc_class)];
        return bundle;
      }
      return Qnil;
    }

### + (`OSX::NSBundle`) bundle_for_class

Returns an instalce of OSX::NSBundle that is main bundle of a given Objective-C class.

Parameters:

- objc_class (`Class`)

Returns:

- (`OSX::NSBundle`)

    115
    116
    117
    118
    119

    # File 'src/objc/mdl_bundle_support.m', line 115

    static VALUE
    rb_bundle_for_class(VALUE mdl, VALUE objc_class)
    {
      return ocid_get_rbobj([gBundleMap objectForKey:_ruby2ocid(objc_class)]);
    }

### + (`Object`) init_for_bundle(option = nil)

Initializes RubyCocoa bundle from Cocoa applications.

See Also:

- OSX.init_for_bundle

    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26

    # File 'src/ruby/osx/objc/oc_bundle_support.rb', line 14

    def init_for_bundle(option = nil)
      ret = nil
      bdl, prm = _current_bundle
      logger = Logger.new(bdl)
      logger.info("init_for_bundle ...") if OSX._debug? || (option && option[:verbose])
      yield(bdl, prm, logger)
      logger.info("init_for_bundle done.") if OSX._debug? || (option && option[:verbose])
      nil
    rescue Exception => err
      logger.error(err)
      logger.info("init_for_bundle failed.")
      raise
    end