Class: NA::Actions
Overview
Actions controller
Instance Method Summary collapse
-
#initialize(actions = []) ⇒ Actions
constructor
A new instance of Actions.
-
#output(depth, files: nil, regexes: [], notes: false, nest: false, nest_projects: false) ⇒ Object
Pretty print a list of actions.
Methods inherited from Array
Constructor Details
#initialize(actions = []) ⇒ Actions
Returns a new instance of Actions.
6 7 8 9 |
# File 'lib/na/actions.rb', line 6 def initialize(actions = []) super concat(actions) end |
Instance Method Details
#output(depth, files: nil, regexes: [], notes: false, nest: false, nest_projects: false) ⇒ Object
Pretty print a list of actions
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/na/actions.rb', line 19 def output(depth, files: nil, regexes: [], notes: false, nest: false, nest_projects: false) return if files.nil? if nest template = NA.theme[:templates][:default] parent_files = {} out = [] if nest_projects each do |action| if parent_files.key?(action.file) parent_files[action.file].push(action) else parent_files[action.file] = [action] end end parent_files.each do |file, acts| projects = NA.project_hierarchy(acts) out.push("#{file.sub(%r{^./}, '').shorten_path}:") out.concat(NA.output_children(projects, 0)) end else template = NA.theme[:templates][:default] each do |action| if parent_files.key?(action.file) parent_files[action.file].push(action) else parent_files[action.file] = [action] end end parent_files.each do |k, v| out.push("#{k.sub(%r{^\./}, '')}:") v.each do |a| out.push("\t- [#{a.parent.join('/')}] #{a.action}") out.push("\t\t#{a.note.join("\n\t\t")}") unless a.note.empty? end end end NA::Pager.page out.join("\n") else template = if files.count.positive? if files.count == 1 NA.theme[:templates][:single_file] else NA.theme[:templates][:multi_file] end elsif NA.find_files(depth: depth).count > 1 if depth > 1 NA.theme[:templates][:multi_file] else NA.theme[:templates][:single_file] end else NA.theme[:templates][:default] end template += '%note' if notes files.map { |f| NA.notify(f, debug: true) } if files output = map { |action| action.pretty(template: { templates: { output: template } }, regexes: regexes, notes: notes) } NA::Pager.page(output.join("\n")) end end |