Class: Bricolage::LogFilePath
- Inherits:
-
Object
- Object
- Bricolage::LogFilePath
- Defined in:
- lib/bricolage/logfilepath.rb
Defined Under Namespace
Classes: Params
Constant Summary collapse
- STD_TEMPLATE =
'%{jobnet_start_date}/%{jobnet}/%{jobnet_start_time}/%{subsystem}-%{job}'
Class Method Summary collapse
Instance Method Summary collapse
- #fill_template(template, params) ⇒ Object
- #format(job_ref:, jobnet_id:, job_start_time:, jobnet_start_time:) ⇒ Object
-
#initialize(template) ⇒ LogFilePath
constructor
A new instance of LogFilePath.
- #job_name(params) ⇒ Object
- #job_start_date(params) ⇒ Object
- #job_start_time(params) ⇒ Object
- #jobnet_id(params) ⇒ Object
- #jobnet_start_date(params) ⇒ Object
- #jobnet_start_time(params) ⇒ Object
- #standard_format(params) ⇒ Object
- #subsystem_name(params) ⇒ Object
Constructor Details
#initialize(template) ⇒ LogFilePath
Returns a new instance of LogFilePath.
13 14 15 |
# File 'lib/bricolage/logfilepath.rb', line 13 def initialize(template) @template = template end |
Class Method Details
.default ⇒ Object
3 4 5 6 7 8 9 10 11 |
# File 'lib/bricolage/logfilepath.rb', line 3 def LogFilePath.default if dir = ENV['BRICOLAGE_LOG_DIR'] new("#{dir}/%{std}.log") elsif path = ENV['BRICOLAGE_LOG_PATH'] new(path) else nil end end |
Instance Method Details
#fill_template(template, params) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bricolage/logfilepath.rb', line 25 def fill_template(template, params) template.gsub(/%\{\w+\}/) {|var| case var when '%{std}' then standard_format(params) when '%{jobnet_start_date}' then jobnet_start_date(params) when '%{jobnet_start_time}' then jobnet_start_time(params) when '%{job_start_date}' then job_start_date(params) when '%{job_start_time}' then job_start_time(params) when '%{jobnet}', '%{net}', '%{jobnet_id}', '%{net_id}', '%{flow}', '%{flow_id}' then jobnet_id(params) when '%{subsystem}' then subsystem_name(params) when '%{job}', '%{job_id}' then job_name(params) else raise ParameterError, "bad log path variable: #{var}" end } end |
#format(job_ref:, jobnet_id:, job_start_time:, jobnet_start_time:) ⇒ Object
17 18 19 20 21 |
# File 'lib/bricolage/logfilepath.rb', line 17 def format(job_ref:, jobnet_id:, job_start_time:, jobnet_start_time:) return nil unless @template params = Params.new(job_ref, jobnet_id, job_start_time, jobnet_start_time) fill_template(@template, params) end |
#job_name(params) ⇒ Object
72 73 74 |
# File 'lib/bricolage/logfilepath.rb', line 72 def job_name(params) params.job_ref.name end |
#job_start_date(params) ⇒ Object
56 57 58 |
# File 'lib/bricolage/logfilepath.rb', line 56 def job_start_date(params) params.start_time.strftime('%Y%m%d') end |
#job_start_time(params) ⇒ Object
60 61 62 |
# File 'lib/bricolage/logfilepath.rb', line 60 def job_start_time(params) params.start_time.strftime('%Y%m%d_%H%M%S%L') end |
#jobnet_id(params) ⇒ Object
64 65 66 |
# File 'lib/bricolage/logfilepath.rb', line 64 def jobnet_id(params) params.jobnet_id.gsub('/', '::') end |
#jobnet_start_date(params) ⇒ Object
48 49 50 |
# File 'lib/bricolage/logfilepath.rb', line 48 def jobnet_start_date(params) params.jobnet_start_time.strftime('%Y%m%d') end |
#jobnet_start_time(params) ⇒ Object
52 53 54 |
# File 'lib/bricolage/logfilepath.rb', line 52 def jobnet_start_time(params) params.jobnet_start_time.strftime('%Y%m%d_%H%M%S%L') end |
#standard_format(params) ⇒ Object
44 45 46 |
# File 'lib/bricolage/logfilepath.rb', line 44 def standard_format(params) fill_template(STD_TEMPLATE, params) end |
#subsystem_name(params) ⇒ Object
68 69 70 |
# File 'lib/bricolage/logfilepath.rb', line 68 def subsystem_name(params) params.job_ref.subsystem end |