Class: RecipeStep
- Inherits:
-
Object
- Object
- RecipeStep
- Defined in:
- lib/baker/bakerlib.rb
Overview
Encapsulate a single date of todo information
Instance Attribute Summary collapse
- #attributes ⇒ Object
-
#line_index ⇒ Object
readonly
matches the index into the parent Recipe.steps.array.
-
#lines ⇒ Object
Lines are expected to contain the line end character ānā.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #command ⇒ Object
- #completed? ⇒ Boolean
- #content ⇒ Object
- #delete ⇒ Object
- #description ⇒ Object
- #directive_type ⇒ Object
-
#indentation_level ⇒ Object
Returns the indentation level (whitespace count) of the first line in this RecipeLine Empty lines are considered to have an indentation level of nil.
-
#initialize(lines, type:, directive_type: nil, content: nil, attributes: nil, command: nil, task_marker: nil, description: nil, line_index: nil) ⇒ RecipeStep
constructor
A new instance of RecipeStep.
- #mark_complete ⇒ Object
- #mark_strikethrough ⇒ Object
- #mark_todo ⇒ Object
-
#single_line_for_display ⇒ Object
Returns the description if any, otherwise the first line of the command with an indication of type ruby or shell Otherwise first line.
- #source_code_line_index ⇒ Object
- #task_marker ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(lines, type:, directive_type: nil, content: nil, attributes: nil, command: nil, task_marker: nil, description: nil, line_index: nil) ⇒ RecipeStep
Returns a new instance of RecipeStep.
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/baker/bakerlib.rb', line 228 def initialize(lines, type: , directive_type: nil, content: nil, attributes: nil, command: nil, task_marker: nil, description: nil, line_index: nil) if lines.is_a?(Array) @lines = lines else @lines = [lines] end @type = type @directive_type = directive_type @content = content @attributes = attributes @command = command @task_marker = task_marker @description = description @line_index = line_index end |
Instance Attribute Details
#attributes ⇒ Object
340 341 342 343 |
# File 'lib/baker/bakerlib.rb', line 340 def attributes raise "Not a directive" if type != :directive return @attributes end |
#line_index ⇒ Object (readonly)
matches the index into the parent Recipe.steps.array
226 227 228 |
# File 'lib/baker/bakerlib.rb', line 226 def line_index @line_index end |
#lines ⇒ Object
Lines are expected to contain the line end character ānā
223 224 225 |
# File 'lib/baker/bakerlib.rb', line 223 def lines @lines end |
#type ⇒ Object
Returns the value of attribute type.
224 225 226 |
# File 'lib/baker/bakerlib.rb', line 224 def type @type end |
Instance Method Details
#command ⇒ Object
345 346 347 348 |
# File 'lib/baker/bakerlib.rb', line 345 def command raise "Not a shell" if type != :shell && type != :ruby return @command end |
#completed? ⇒ Boolean
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 |
# File 'lib/baker/bakerlib.rb', line 272 def completed? case type when :directive case directive_type when :var return attributes != nil when :template return false when :template_source return false when :cd return false end raise "Unknown directive type: #{directive_type}" when :shell, :manual, :ruby return task_marker != " " else return true end end |
#content ⇒ Object
335 336 337 338 |
# File 'lib/baker/bakerlib.rb', line 335 def content raise "RecipeStep.content is only valid for a directive, but is #{type}" if type != :directive return @content end |
#delete ⇒ Object
244 245 246 |
# File 'lib/baker/bakerlib.rb', line 244 def delete self.lines = [] end |
#description ⇒ Object
355 356 357 |
# File 'lib/baker/bakerlib.rb', line 355 def description return @description end |
#directive_type ⇒ Object
330 331 332 333 |
# File 'lib/baker/bakerlib.rb', line 330 def directive_type raise "Not a directive" if type != :directive return @directive_type end |
#indentation_level ⇒ Object
Returns the indentation level (whitespace count) of the first line in this RecipeLine Empty lines are considered to have an indentation level of nil
315 316 317 318 |
# File 'lib/baker/bakerlib.rb', line 315 def indentation_level return nil if !lines || lines.size == 0 || lines[0].strip.length == 0 return lines[0][/\A\s*/].length end |
#mark_complete ⇒ Object
293 294 295 296 297 298 299 300 301 |
# File 'lib/baker/bakerlib.rb', line 293 def mark_complete if lines[0] =~ /\[\s\]/ lines[0].sub!(/\[\s\]/, "[x]") @task_marker = "x" else puts lines.inspect raise end end |
#mark_strikethrough ⇒ Object
303 304 305 306 307 308 309 310 311 |
# File 'lib/baker/bakerlib.rb', line 303 def mark_strikethrough if lines[0] =~ /\[\s\]/ lines[0].sub!(/\[\s\]/, "[-]") @task_marker = "-" else puts lines.inspect raise end end |
#mark_todo ⇒ Object
320 321 322 323 324 325 326 327 328 |
# File 'lib/baker/bakerlib.rb', line 320 def mark_todo if lines[0] =~ /\[[xX\-.y]\]/ lines[0].sub!(/\[[xX\-.y]\]/, "[ ]") @task_marker = " " else puts lines.inspect raise end end |
#single_line_for_display ⇒ Object
Returns the description if any, otherwise the first line of the command with an indication of type ruby or shell Otherwise first line
254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/baker/bakerlib.rb', line 254 def single_line_for_display if description && description.strip.size > 0 return description end if command && command.strip.size > 0 return "#{type} command - " + (command.split("\n").first == command ? command : command.split("\n").first + "...").strip end s = to_s return '<empty line>' if s.strip.size == 0 return (s.split("\n").first == s ? s : s.split("\n").first + "...").strip end |
#source_code_line_index ⇒ Object
268 269 270 |
# File 'lib/baker/bakerlib.rb', line 268 def source_code_line_index return @line_index + 1 end |
#task_marker ⇒ Object
350 351 352 353 |
# File 'lib/baker/bakerlib.rb', line 350 def task_marker raise "Not a task" if type != :shell && type != :manual && type != :ruby return @task_marker end |
#to_s ⇒ Object
248 249 250 |
# File 'lib/baker/bakerlib.rb', line 248 def to_s lines.join end |