class Prettyp::Formatter::BaseFormatter
Public Class Methods
check_requirement()
click to toggle source
# File lib/prettyp/formatter/base_formatter.rb, line 20 def self.check_requirement raise Unimplemented 'requirement' end
inherited(clazz)
click to toggle source
# File lib/prettyp/formatter/base_formatter.rb, line 11 def self.inherited clazz @inherited_classes ||= [] @inherited_classes << clazz end
inherited_classes()
click to toggle source
# File lib/prettyp/formatter/base_formatter.rb, line 16 def self.inherited_classes @inherited_classes end
languages()
click to toggle source
# File lib/prettyp/formatter/base_formatter.rb, line 24 def self.languages [] end
Public Instance Methods
check_requirement()
click to toggle source
# File lib/prettyp/formatter/base_formatter.rb, line 28 def check_requirement self.class.check_requirement end
format(input, language)
click to toggle source
# File lib/prettyp/formatter/base_formatter.rb, line 32 def format input, language raise Unimplemented 'format' end
Protected Instance Methods
execute_command(command, on_error: nil, on_success: nil)
click to toggle source
# File lib/prettyp/formatter/base_formatter.rb, line 37 def execute_command command, on_error: nil, on_success: nil logger.debug command output = `#{command} 2>&1 ` success = !execute_error? on_error.call(output) if !success && on_error on_success.call(output) if success and on_success output end
execute_error?()
click to toggle source
# File lib/prettyp/formatter/base_formatter.rb, line 49 def execute_error? $? != 0 end
with_file(input, &block)
click to toggle source
# File lib/prettyp/formatter/base_formatter.rb, line 53 def with_file input, &block return block.call(input) if input.is_a?(File) || input.is_a?(Tempfile) with_tempfile(input, &block) end
with_tempfile(input, &block)
click to toggle source
# File lib/prettyp/formatter/base_formatter.rb, line 58 def with_tempfile input, &block file = Tempfile.new('prettyp') file.write(input) begin file.rewind block.call(file) ensure file.close file.unlink end end