Class: SyntaxTree::CLI::Check

Inherits:
Action
  • Object
show all
Defined in:
lib/syntax_tree/cli.rb

Overview

An action of the CLI that ensures that the filepath is formatted as expected.

Defined Under Namespace

Classes: UnformattedError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(print_width:) ⇒ Check

Returns a new instance of Check.



96
97
98
# File 'lib/syntax_tree/cli.rb', line 96

def initialize(print_width:)
  @print_width = print_width
end

Instance Attribute Details

Returns the value of attribute print_width.



94
95
96
# File 'lib/syntax_tree/cli.rb', line 94

def print_width
  @print_width
end

Instance Method Details

#failureObject



114
115
116
# File 'lib/syntax_tree/cli.rb', line 114

def failure
  warn("The listed files did not match the expected format.")
end

#run(item) ⇒ Object



100
101
102
103
104
105
106
107
108
# File 'lib/syntax_tree/cli.rb', line 100

def run(item)
  source = item.source
  if source != item.handler.format(source, print_width)
    raise UnformattedError
  end
rescue StandardError
  warn("[#{Color.yellow("warn")}] #{item.filepath}")
  raise
end

#successObject



110
111
112
# File 'lib/syntax_tree/cli.rb', line 110

def success
  puts("All files matched expected format.")
end