module Locd::Agent::System::ClassMethods

Mixed in to classes themselves that include {Locd::Agent::System}.

Public Instance Methods

add(**kwds) click to toggle source

Wrapper that passes keywords though {#default_write_kwds} before calling the super method.

@param (see Locd::Agent.add) @return (see Locd::Agent.add) @raise (see Locd::Agent.add)

Calls superclass method
# File lib/locd/agent/system.rb, line 297
def add **kwds
  super **default_write_kwds( **kwds )
end
create_plist_data(**kwds) click to toggle source

Wrapper that passes keywords though {#default_write_kwds} before calling the super method.

@param (see Locd::Agent.create_plist_data) @return (see Locd::Agent.create_plist_data) @raise (see Locd::Agent.create_plist_data)

Calls superclass method
# File lib/locd/agent/system.rb, line 285
def create_plist_data **kwds
  super **default_write_kwds( **kwds )
end
default_log_path(workdir, label) click to toggle source

By default system agent logs are placed in the Loc'd log directory, which is `<locd_home>/log` and named `<label>.log`.

It does not depend on the `workdir` parameter at all - `workdir` is only included to conform to the {Locd::Agent.default_log_path} signature.

@example

# Considering
Locd.config.log_dir
# => #<Pathname:/Users/nrser/.locd/log>

# then
default_log_path _, 'com.nrser.locd.proxy'
# => #<Pathname:/Users/nrser/.locd/log/com.nrser.locd.proxy.log>

@see Locd::Config#log_dir @see Locd.config @see Locd::Agent.default_log_path

@param [Pathname] workdir

Not used.

@param [String] label

The agent's label.

@return [Pathname]

Absolute path to the log file.
# File lib/locd/agent/system.rb, line 178
def default_log_path workdir, label
  Locd.config.log_dir / "#{ label }.log"
end
default_write_kwds(bin: Locd.config[:bin], workdir: Locd.config.home_dir, **kwds) click to toggle source

Wrapper that keyword arguments to `.add` and `.create_plist_data` are passed through before forwarding up to the super method.

Provides default values and checks that necessary values like `label` and `is_system` are either not provided in the call or match the expected values.

@param [String] bin:

The executable that will be used by system agents to call Loc'd.

@param workdir: (see Locd::Agent.add)

@param **kwds

Merged into the returned {Hash}.

@raise [ArgumentError]

If `kwds` contains bad values.
# File lib/locd/agent/system.rb, line 232
    def default_write_kwds  bin: Locd.config[:bin],
                            workdir: Locd.config.home_dir,
                            **kwds
      
      if kwds.key?( :is_system ) && kwds[:is_system] != true
        raise ArgumentError.new binding.erb <<~END
          The `:is_system` keyword **must** be `true` for system agents.
          
          It's how we recognize them!
          
          Found
          
              <%= kwds[:is_system] %>
          
        END
      end
      
      if kwds.key?( :label ) && kwds[:label] != self.label
        raise ArgumentError.new binding.erb <<~END
          Can not customize system agent labels!
          
          It **must** be `<%= self.label %>`, because that's how Loc'd finds it.
          
          You can change the part before the `.proxy` via the
          
              locd.namespace.label
          
          configuration value. Create or edit the file at
          
              <%= Locd.config.user_config_path %>
          
          to define overrides (nested YAML hashes, deep merged).
          
        END
      end
      
      {
        bin: bin.to_s,
        workdir: workdir,
        **kwds,
        is_system: true,
        label: self.label,
      }
    end
get(label = self.label) click to toggle source

Get the agent.

@return [Locd::Agent]

If the agent exists.

@return [nil]

If the agent does not exist.
Calls superclass method
# File lib/locd/agent/system.rb, line 194
def get label = self.label
  unless label == self.label
    raise NRSER::AttributeError.new \
      "System agents have a fixed label, must be", self.label
  end
  
  super( label )
end
get!(label = self.label) click to toggle source
Calls superclass method
# File lib/locd/agent/system.rb, line 204
def get! label = self.label
  super( label )
end
label() click to toggle source
# File lib/locd/agent/system.rb, line 124
def label
  "#{ Locd.config[:namespace, :label] }.#{ label_name }"
end
plist?(plist) click to toggle source

The property lists for system agents are identified by their unique label (unique to the label namespace).

@param (see Locd::Agent.plist?) @return (see Locd::Agent.plist?)

# File lib/locd/agent/system.rb, line 135
def plist? plist
  plist['Label'] == self.label
end
plist_abs_path(label = self.label) click to toggle source

Overridden as convenience, defaults the label to `.label`.

@param (see Locd::Agent.plist_abs_path) @return (see Locd::Agent.plist_abs_path)

Calls superclass method
# File lib/locd/agent/system.rb, line 145
def plist_abs_path label = self.label
  super label
end