Sha256: 20cec43da771ecf02f6fe43f80949a33e76aa6ef276e8209d1d3fc5aecab191f

Contents?: true

Size: 951 Bytes

Versions: 1

Compression:

Stored size: 951 Bytes

Contents

# frozen_string_literal: true

require 'rainbow'
require_relative 'check_input/input_data'

class CheckInput
  def initialize(verbose = true)
    @verbose = verbose
  end

  def file(filepath)
    @filepath = filepath
    self
  end

  def verbose(verbose)
    @verbose = verbose
    self
  end

  def check
    # Check HAML file syntax
    exist = check_file_exist
    return false unless exist
    check_file_content
  end

  private

  def check_file_exist
    if @filepath.nil?
      raise Rainbow("Can't check nil filename")
    end
    unless File.exist? @filepath
      puts Rainbow('File not found!').red.bright if @verbose
      return false
    end
    unless File.extname(@filepath) == '.haml'
      puts Rainbow('Only check HAML files!').yellow.bright if @verbose
      return false
    end
    true
  end

  def check_file_content
    data = InputData.new(@filepath)
    data.check
    data.show_errors if @verbose
    data.ok?
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
asker-tool-2.2.2 lib/asker/check_input.rb