Class: OsCtld::KernelParams
- Inherits:
-
Object
- Object
- OsCtld::KernelParams
- Includes:
- Singleton
- Defined in:
- lib/osctld/kernel_params.rb
Overview
Interface to kernel command line parameters
Instance Attribute Summary collapse
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#autostart_cts? ⇒ Boolean
Check parameter osctl.autostart.
- #cache(name) ⇒ Object protected
-
#import_pools? ⇒ Boolean
Check parameter osctl.pools.
-
#include?(name) ⇒ Boolean
Check if parameter is set.
-
#initialize ⇒ KernelParams
constructor
A new instance of KernelParams.
-
#read_kv(k, default_v) ⇒ String
Extract key-value parameter.
Constructor Details
#initialize ⇒ KernelParams
Returns a new instance of KernelParams.
18 19 20 21 |
# File 'lib/osctld/kernel_params.rb', line 18 def initialize @cache = {} @params = File.read('/proc/cmdline').strip.split end |
Instance Attribute Details
#params ⇒ Object (readonly)
Returns the value of attribute params.
16 17 18 |
# File 'lib/osctld/kernel_params.rb', line 16 def params @params end |
Instance Method Details
#autostart_cts? ⇒ Boolean
Check parameter osctl.autostart
Enabled by default.
57 58 59 |
# File 'lib/osctld/kernel_params.rb', line 57 def autostart_cts? cache(:autostart) { read_kv('osctl.autostart', '1') == '1' } end |
#cache(name) ⇒ Object (protected)
63 64 65 66 67 |
# File 'lib/osctld/kernel_params.rb', line 63 def cache(name) return @cache[name] if @cache.has_key?(name) @cache[name] = yield end |
#import_pools? ⇒ Boolean
Check parameter osctl.pools
Enabled by default.
50 51 52 |
# File 'lib/osctld/kernel_params.rb', line 50 def import_pools? cache(:pools) { read_kv('osctl.pools', '1') == '1' } end |
#include?(name) ⇒ Boolean
Check if parameter is set
25 26 27 |
# File 'lib/osctld/kernel_params.rb', line 25 def include?(name) params.include?(name) end |
#read_kv(k, default_v) ⇒ String
Extract key-value parameter
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/osctld/kernel_params.rb', line 33 def read_kv(k, default_v) params.each do |param| eq = param.index('=') next if eq.nil? param_k = param[0..eq - 1] next if param_k != k return param[eq + 1..] end default_v end |