Module: Locd::Agent::System
- Included in:
- Proxy, RotateLogs
- Defined in:
- lib/locd/agent/system.rb
Overview
Mixin for common stuff that system agents do different.
System agents are specific types of Locd::Agent built in to Loc'd to handle things like proxying HTTP request site (Proxy), rotating logs so they don't get unwieldily (RotaeLogs), and probably more in the future, like serving a site index, API, etc.
System agents are singular - there's only one of each for a Loc'd
label namespace, which is set via the configuration, and Loc'd uses
that label namespace, together with the each system agent's .label_name,
to form the agent's unique label, which is how it finds the system agents.
This was really just to make it simpler by side-stepping how to handle many proxies and log rotators and such because besides the dev/release situation described above I can't really think of any reason you would want to create and manage multiple of each system agent.
As a consequence, Locd::Agent subclasses that mix System
in must define a .label_name class method.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- @@classes =
Hamster::Set.new
Class Method Summary collapse
-
.class_for(plist) ⇒ Class<Locd::Agent>?
Find the concrete Locd::Agent subclass (that has mixed in System) for a property list.
- .classes ⇒ Object
- .included(base) ⇒ Object
-
.instance_label?(label) ⇒ Boolean
Is an agent label for a system agent of this Loc'd instance?.
-
.instance_plist?(plist) ⇒ Boolean
Is a plist for a system agent of this Loc'd instance?.
-
.plist?(plist) ⇒ Boolean
Is the plist for a system agent of any Loc'd instance?.
Class Method Details
.class_for(plist) ⇒ Class<Locd::Agent>?
Find the concrete Locd::Agent subclass (that has mixed in Locd::Agent::System) for a property list.
107 108 109 110 111 |
# File 'lib/locd/agent/system.rb', line 107 def self.class_for plist return nil unless plist?( plist ) classes.to_a.find_bounded( max: 1 ) { |cls| cls.plist? plist }.first end |
.classes ⇒ Object
38 39 40 |
# File 'lib/locd/agent/system.rb', line 38 def self.classes @@classes end |
.included(base) ⇒ Object
114 115 116 117 |
# File 'lib/locd/agent/system.rb', line 114 def self.included base base.extend ClassMethods @@classes = @@classes.add base end |
.instance_label?(label) ⇒ Boolean
We can't tell if a label is a system agent label for any Loc'd instance
since the prefix can be configured to anything (via the
locd:namespace:label key).
Is an agent label for a system agent of this Loc'd instance?
52 53 54 55 |
# File 'lib/locd/agent/system.rb', line 52 def self.instance_label? label label.is_a?( String ) && label.start_with?( "#{ Locd.config[:namespace, :label] }." ) end |
.instance_plist?(plist) ⇒ Boolean
Is a plist for a system agent of this Loc'd instance?
84 85 86 |
# File 'lib/locd/agent/system.rb', line 84 def self.instance_plist? plist plist?( plist ) && instance_label?( plist[ 'Label' ] ) end |
.plist?(plist) ⇒ Boolean
Is the plist for a system agent of any Loc'd instance?
In case it's not obvious, this tests true given plists of system agents of other Loc'd instance configurations besides just this one, which can be useful to weed things out. Maybe.
69 70 71 |
# File 'lib/locd/agent/system.rb', line 69 def self.plist? plist plist.dig( Locd.config[:agent, :config_key], 'is_system' ) == true end |