Class: SyntaxTree::CLI::Write
Overview
An action of the CLI that formats the input source and writes the formatted output back to the file.
Instance Attribute Summary collapse
-
#print_width ⇒ Object
readonly
Returns the value of attribute print_width.
Instance Method Summary collapse
-
#initialize(print_width:) ⇒ Write
constructor
A new instance of Write.
- #run(item) ⇒ Object
Methods inherited from Action
Constructor Details
#initialize(print_width:) ⇒ Write
Returns a new instance of Write.
200 201 202 |
# File 'lib/syntax_tree/cli.rb', line 200 def initialize(print_width:) @print_width = print_width end |
Instance Attribute Details
#print_width ⇒ Object (readonly)
Returns the value of attribute print_width.
198 199 200 |
# File 'lib/syntax_tree/cli.rb', line 198 def print_width @print_width end |
Instance Method Details
#run(item) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/syntax_tree/cli.rb', line 204 def run(item) filepath = item.filepath start = Time.now source = item.source formatted = item.handler.format(source, print_width) File.write(filepath, formatted) if filepath != :stdin color = source == formatted ? Color.gray(filepath) : filepath delta = ((Time.now - start) * 1000).round puts "#{color} #{delta}ms" rescue StandardError puts filepath raise end |