Class: Locd::Newsyslog::Entry
- Inherits:
-
Object
- Object
- Locd::Newsyslog::Entry
- Defined in:
- lib/locd/newsyslog.rb
Overview
Lil' class that holds values for a newsyslog conf file entry.
Constant Summary collapse
- WHEN_NEVER =
Value for the
whenfield when we want to never rotate based on time. '*'- NO_FLAGS =
Conf file value for
flagswhere there are none '-'- FIELD_SEP =
" "
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Attributes ======================================================================.
-
#flags ⇒ Object
readonly
Attributes ======================================================================.
-
#group ⇒ Object
readonly
Attributes ======================================================================.
-
#log_path ⇒ Object
readonly
Attributes ======================================================================.
-
#mode ⇒ Object
readonly
Attributes ======================================================================.
-
#owner ⇒ Object
readonly
Attributes ======================================================================.
-
#pid_path ⇒ Object
readonly
Attributes ======================================================================.
-
#sig_num ⇒ Object
readonly
Attributes ======================================================================.
-
#size ⇒ Object
readonly
Attributes ======================================================================.
-
#when_ ⇒ Object
readonly
Attributes ======================================================================.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(log_path:, pid_path:, owner: nil, group: nil, mode: '644', count: 7, size: 100, when_: '*', flags: [], signal: 'HUP') ⇒ Entry
constructor
Instantiate a new
Entry. - #render ⇒ Object
- #render_flags ⇒ Object
-
#sig_name ⇒ Object
Instance Methods ======================================================================.
Constructor Details
#initialize(log_path:, pid_path:, owner: nil, group: nil, mode: '644', count: 7, size: 100, when_: '*', flags: [], signal: 'HUP') ⇒ Entry
Instantiate a new Entry.
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/locd/newsyslog.rb', line 128 def initialize log_path:, pid_path:, owner: nil, group: nil, mode: '644', count: 7, size: 100, # 100 KB max size when_: '*', # '$D0', # rotate every day at midnight flags: [], signal: 'HUP' @log_path = log_path @pid_path = pid_path @owner = owner @group = group @mode = self.class.mode_string_for mode @count = t.pos_int.check count @size = t.pos_int.check size @when_ = when_ @flags = flags @sig_num = self.class.sig_num_for signal render end |
Instance Attribute Details
#count ⇒ Object (readonly)
Attributes
113 114 115 |
# File 'lib/locd/newsyslog.rb', line 113 def count @count end |
#flags ⇒ Object (readonly)
Attributes
113 114 115 |
# File 'lib/locd/newsyslog.rb', line 113 def flags @flags end |
#group ⇒ Object (readonly)
Attributes
113 114 115 |
# File 'lib/locd/newsyslog.rb', line 113 def group @group end |
#log_path ⇒ Object (readonly)
Attributes
113 114 115 |
# File 'lib/locd/newsyslog.rb', line 113 def log_path @log_path end |
#mode ⇒ Object (readonly)
Attributes
113 114 115 |
# File 'lib/locd/newsyslog.rb', line 113 def mode @mode end |
#owner ⇒ Object (readonly)
Attributes
113 114 115 |
# File 'lib/locd/newsyslog.rb', line 113 def owner @owner end |
#pid_path ⇒ Object (readonly)
Attributes
113 114 115 |
# File 'lib/locd/newsyslog.rb', line 113 def pid_path @pid_path end |
#sig_num ⇒ Object (readonly)
Attributes
113 114 115 |
# File 'lib/locd/newsyslog.rb', line 113 def sig_num @sig_num end |
#size ⇒ Object (readonly)
Attributes
113 114 115 |
# File 'lib/locd/newsyslog.rb', line 113 def size @size end |
#when_ ⇒ Object (readonly)
Attributes
113 114 115 |
# File 'lib/locd/newsyslog.rb', line 113 def when_ @when_ end |
Class Method Details
.mode_string_for(mode) ⇒ return_type
Document normalize_mode method.
Returns @todo Document return value.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/locd/newsyslog.rb', line 80 def self.mode_string_for mode # t.match mode, # 0000..0777, mode.to_s( 8 ), # /\A[0-7]{3}\z/, mode case mode when 0000..0777 mode.to_s 8 when /\A[0-7]{3}\z/ mode else raise ArgumentError, "Bad mode: #{ mode.inspect }, need String or Fixnum: '644'; 0644" end end |
.sig_num_for(signal) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/locd/newsyslog.rb', line 97 def self.sig_num_for signal case signal when String Signal.list.fetch signal when Fixnum signal else raise ArgumentError, "Bad signal: #{ signal.inspect }, need String or Fixnum: 'HUP'; 1" end end |
Instance Method Details
#render ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
# File 'lib/locd/newsyslog.rb', line 170 def render @render ||= begin fields = [ log_path, "#{ owner }:#{ group }", mode, count, size, when_, render_flags, ] if pid_path fields << pid_path fields << sig_num end fields.map( &:to_s ).join FIELD_SEP end end |
#render_flags ⇒ Object
161 162 163 164 165 166 167 |
# File 'lib/locd/newsyslog.rb', line 161 def render_flags if flags.empty? NO_FLAGS else flags.join end end |
#sig_name ⇒ Object
Instance Methods
156 157 158 |
# File 'lib/locd/newsyslog.rb', line 156 def sig_name Signal.signame @sig_num end |