Class: Dk::Config
Defined Under Namespace
Classes: DryTreeStub, LogslyLogger
Constant Summary
collapse
- UnknownTaskError =
Class.new(ArgumentError) do
def initialize(task_name)
super("No task named #{task_name}")
end
end
- DEFAULT_INIT_PROCS =
[].freeze
- DEFAULT_PARAMS =
{}.freeze
- DEFAULT_CALLBACKS =
Hash.new{ |h, k| h[k] = Dk::Task::CallbackSet.new }.freeze
- DEFAULT_SSH_HOSTS =
{}.freeze
- DEFAULT_SSH_ARGS =
''.freeze
- DEFAULT_HOST_SSH_ARGS =
Hash.new{ |h, k| h[k] = DEFAULT_SSH_ARGS }
- DEFAULT_TASKS =
Hash.new{ |h, k| raise UnknownTaskError.new("`#{k}`") }.freeze
- DEFAULT_LOG_PATTERN =
"%m\n".freeze
- DEFAULT_LOG_FILE_PATTERN =
'[%d %-5l] : %m\n'.freeze
- DEFAULT_STDOUT_LOG_LEVEL =
'info'.freeze
- DEFAULT_STUBS =
[].freeze
- FILE_LOG_LEVEL =
'debug'.freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#after(subject_task_class, callback_task_class, params = nil) ⇒ Object
-
#after_callback_task_classes(for_task_class) ⇒ Object
-
#before(subject_task_class, callback_task_class, params = nil) ⇒ Object
-
#before_callback_task_classes(for_task_class) ⇒ Object
-
#dk_logger ⇒ Object
-
#dk_logger_file_output_name ⇒ Object
-
#dk_logger_stdout_output_name ⇒ Object
private - intended for internal use only.
-
#init ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#log_file(value = nil) ⇒ Object
-
#log_file_pattern(value = nil) ⇒ Object
-
#log_pattern(value = nil) ⇒ Object
-
#prepend_after(subject_task_class, callback_task_class, params = nil) ⇒ Object
-
#prepend_after_callback_task_classes(for_task_class) ⇒ Object
-
#prepend_before(subject_task_class, callback_task_class, params = nil) ⇒ Object
-
#prepend_before_callback_task_classes(for_task_class) ⇒ Object
-
#set_param(key, value) ⇒ Object
-
#stdout_log_level(value = nil) ⇒ Object
-
#stub_dry_tree_cmd(cmd_str, args = nil, &block) ⇒ Object
-
#stub_dry_tree_ssh(cmd_str, args = nil, &block) ⇒ Object
-
#task(name, task_class = nil) ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
Instance Attribute Details
#after_callbacks ⇒ Object
Returns the value of attribute after_callbacks.
33
34
35
|
# File 'lib/dk/config.rb', line 33
def after_callbacks
@after_callbacks
end
|
#before_callbacks ⇒ Object
Returns the value of attribute before_callbacks.
32
33
34
|
# File 'lib/dk/config.rb', line 32
def before_callbacks
@before_callbacks
end
|
#dry_tree_cmd_stubs ⇒ Object
Returns the value of attribute dry_tree_cmd_stubs.
34
35
36
|
# File 'lib/dk/config.rb', line 34
def dry_tree_cmd_stubs
@dry_tree_cmd_stubs
end
|
#dry_tree_ssh_stubs ⇒ Object
Returns the value of attribute dry_tree_ssh_stubs.
34
35
36
|
# File 'lib/dk/config.rb', line 34
def dry_tree_ssh_stubs
@dry_tree_ssh_stubs
end
|
#init_procs ⇒ Object
Returns the value of attribute init_procs.
31
32
33
|
# File 'lib/dk/config.rb', line 31
def init_procs
@init_procs
end
|
#params ⇒ Object
Returns the value of attribute params.
31
32
33
|
# File 'lib/dk/config.rb', line 31
def params
@params
end
|
#prepend_after_callbacks ⇒ Object
Returns the value of attribute prepend_after_callbacks.
33
34
35
|
# File 'lib/dk/config.rb', line 33
def prepend_after_callbacks
@prepend_after_callbacks
end
|
#prepend_before_callbacks ⇒ Object
Returns the value of attribute prepend_before_callbacks.
32
33
34
|
# File 'lib/dk/config.rb', line 32
def prepend_before_callbacks
@prepend_before_callbacks
end
|
#tasks ⇒ Object
Returns the value of attribute tasks.
34
35
36
|
# File 'lib/dk/config.rb', line 34
def tasks
@tasks
end
|
Instance Method Details
#after(subject_task_class, callback_task_class, params = nil) ⇒ Object
77
78
79
80
81
82
|
# File 'lib/dk/config.rb', line 77
def after(subject_task_class, callback_task_class, params = nil)
self.after_callbacks[subject_task_class] << Task::Callback.new(
callback_task_class,
params
)
end
|
#after_callback_task_classes(for_task_class) ⇒ Object
99
100
101
|
# File 'lib/dk/config.rb', line 99
def after_callback_task_classes(for_task_class)
self.after_callbacks[for_task_class].map(&:task_class)
end
|
#before(subject_task_class, callback_task_class, params = nil) ⇒ Object
63
64
65
66
67
68
|
# File 'lib/dk/config.rb', line 63
def before(subject_task_class, callback_task_class, params = nil)
self.before_callbacks[subject_task_class] << Task::Callback.new(
callback_task_class,
params
)
end
|
#before_callback_task_classes(for_task_class) ⇒ Object
91
92
93
|
# File 'lib/dk/config.rb', line 91
def before_callback_task_classes(for_task_class)
self.before_callbacks[for_task_class].map(&:task_class)
end
|
#dk_logger ⇒ Object
173
174
175
|
# File 'lib/dk/config.rb', line 173
def dk_logger
@dk_logger ||= LogslyLogger.new(self)
end
|
#dk_logger_file_output_name ⇒ Object
168
169
170
171
|
# File 'lib/dk/config.rb', line 168
def dk_logger_file_output_name
@dk_logger_file_output_name ||= "dk-config-#{self.object_id}-file"
end
|
#dk_logger_stdout_output_name ⇒ Object
private - intended for internal use only
163
164
165
166
|
# File 'lib/dk/config.rb', line 163
def dk_logger_stdout_output_name
@dk_logger_stdout_output_name ||= "dk-config-#{self.object_id}-stdout"
end
|
#init ⇒ Object
55
56
57
|
# File 'lib/dk/config.rb', line 55
def init
self.init_procs.each{ |block| self.instance_eval(&block) }
end
|
#log_file(value = nil) ⇒ Object
127
128
129
130
|
# File 'lib/dk/config.rb', line 127
def log_file(value = nil)
@log_file = value if !value.nil?
@log_file
end
|
#log_file_pattern(value = nil) ⇒ Object
132
133
134
135
|
# File 'lib/dk/config.rb', line 132
def log_file_pattern(value = nil)
@log_file_pattern = value if !value.nil?
@log_file_pattern
end
|
#log_pattern(value = nil) ⇒ Object
122
123
124
125
|
# File 'lib/dk/config.rb', line 122
def log_pattern(value = nil)
@log_pattern = value if !value.nil?
@log_pattern
end
|
#prepend_after(subject_task_class, callback_task_class, params = nil) ⇒ Object
84
85
86
87
88
89
|
# File 'lib/dk/config.rb', line 84
def prepend_after(subject_task_class, callback_task_class, params = nil)
self.prepend_after_callbacks[subject_task_class].unshift(Task::Callback.new(
callback_task_class,
params
))
end
|
#prepend_after_callback_task_classes(for_task_class) ⇒ Object
103
104
105
|
# File 'lib/dk/config.rb', line 103
def prepend_after_callback_task_classes(for_task_class)
self.prepend_after_callbacks[for_task_class].map(&:task_class)
end
|
#prepend_before(subject_task_class, callback_task_class, params = nil) ⇒ Object
70
71
72
73
74
75
|
# File 'lib/dk/config.rb', line 70
def prepend_before(subject_task_class, callback_task_class, params = nil)
self.prepend_before_callbacks[subject_task_class].unshift(Task::Callback.new(
callback_task_class,
params
))
end
|
#prepend_before_callback_task_classes(for_task_class) ⇒ Object
95
96
97
|
# File 'lib/dk/config.rb', line 95
def prepend_before_callback_task_classes(for_task_class)
self.prepend_before_callbacks[for_task_class].map(&:task_class)
end
|
#set_param(key, value) ⇒ Object
59
60
61
|
# File 'lib/dk/config.rb', line 59
def set_param(key, value)
self.params.merge!(dk_normalize_params(key => value))
end
|
#stdout_log_level(value = nil) ⇒ Object
117
118
119
120
|
# File 'lib/dk/config.rb', line 117
def stdout_log_level(value = nil)
@stdout_log_level = value if !value.nil?
@stdout_log_level
end
|
#stub_dry_tree_cmd(cmd_str, args = nil, &block) ⇒ Object
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/dk/config.rb', line 137
def stub_dry_tree_cmd(cmd_str, args = nil, &block)
args ||= {}
cmd_str_proc = get_cmd_ssh_proc(cmd_str)
input_proc = get_cmd_ssh_proc(args[:input])
given_opts_proc = get_cmd_ssh_proc(args[:opts])
@dry_tree_cmd_stubs.unshift(
DryTreeStub.new(cmd_str_proc, input_proc, given_opts_proc, block)
)
end
|
#stub_dry_tree_ssh(cmd_str, args = nil, &block) ⇒ Object
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/dk/config.rb', line 149
def stub_dry_tree_ssh(cmd_str, args = nil, &block)
args ||= {}
cmd_str_proc = get_cmd_ssh_proc(cmd_str)
input_proc = get_cmd_ssh_proc(args[:input])
given_opts_proc = get_cmd_ssh_proc(args[:opts])
@dry_tree_ssh_stubs.unshift(
DryTreeStub.new(cmd_str_proc, input_proc, given_opts_proc, block)
)
end
|
#task(name, task_class = nil) ⇒ Object
107
108
109
110
111
112
113
114
115
|
# File 'lib/dk/config.rb', line 107
def task(name, task_class = nil)
if !task_class.nil?
if !task_class.kind_of?(Class) || !task_class.include?(Dk::Task)
raise ArgumentError, "#{task_class.inspect} is not a Dk::Task"
end
@tasks[name.to_s] = task_class
end
@tasks[name.to_s]
end
|