Class: Plist4r::PlistType::Launchd::Sockets

Inherits:
ArrayDict show all
Defined in:
lib/plist4r/plist_type/launchd.rb

Defined Under Namespace

Classes: Socket

Constant Summary

Constants included from DataMethods

DataMethods::ClassesForKeyType, DataMethods::ValidKeys, DataMethods::ValidKeysTemplate

Instance Method Summary collapse

Methods inherited from ArrayDict

#hash, #initialize, #select, #select_all, #to_hash, #unselect, #unselect_all

Methods included from DataMethods

#_respond_to?, #method_missing, #set_or_return, #set_or_return_of_type, #validate_value

Constructor Details

This class inherits a constructor from Plist4r::ArrayDict

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Plist4r::DataMethods

Instance Method Details

#add_socket(plicity, key, index = nil, &blk) ⇒ Object



507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
# File 'lib/plist4r/plist_type/launchd.rb', line 507

def add_socket plicity, key, index=nil, &blk
  select_all
  if plicity == :implicit
    if index && @orig[key].class != Array
      raise "Implicit \"Listeners\" socket already exists, and is of a different type (not array of hashes). Override with: socket \"Listeners\" #{index} &blk"
    elsif @orig[key]
      raise "Implicit \"Listeners\" socket already exists, value: #{orig[key]}. Override with: socket \"Listeners\" &blk"
    end
  end
  if index
    add_socket_to_array key, index, &blk
  else
    add_socket_to_dictionary key, &blk
  end
end

#add_socket_to_array(key, index, &blk) ⇒ Object



501
502
503
504
505
# File 'lib/plist4r/plist_type/launchd.rb', line 501

def add_socket_to_array key, index, &blk
  @orig[key] = [] unless @orig[key].class == Array
  @hash[key] ||= []
  @hash[key][index] = Sockets::Socket.new(@orig[key],index,&blk).to_hash
end

#add_socket_to_dictionary(key, &blk) ⇒ Object



497
498
499
# File 'lib/plist4r/plist_type/launchd.rb', line 497

def add_socket_to_dictionary key, &blk
  @hash[key] = Sockets::Socket.new(@hash[key],&blk).to_hash
end