Sha256: 2d788e16b43f5f7b3e2492f7a1e15631eb37a05a82a29d743c9261ddc313bedf

Contents?: true

Size: 960 Bytes

Versions: 22

Compression:

Stored size: 960 Bytes

Contents

# frozen_string_literal: true

require 'rainbow'
require_relative 'check_input/check_haml_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 = CheckHamlData.new(@filepath)
    data.check
    data.show_errors if @verbose
    data.ok?
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
asker-tool-2.5.7 lib/asker/check_input.rb
asker-tool-2.5.6 lib/asker/check_input.rb
asker-tool-2.5.5 lib/asker/check_input.rb
asker-tool-2.5.4 lib/asker/check_input.rb
asker-tool-2.5.3 lib/asker/check_input.rb
asker-tool-2.5.2 lib/asker/check_input.rb
asker-tool-2.5.1 lib/asker/check_input.rb
asker-tool-2.5.0 lib/asker/check_input.rb
asker-tool-2.4.5 lib/asker/check_input.rb
asker-tool-2.4.4 lib/asker/check_input.rb
asker-tool-2.4.3 lib/asker/check_input.rb
asker-tool-2.4.2 lib/asker/check_input.rb
asker-tool-2.4.1 lib/asker/check_input.rb
asker-tool-2.4.0 lib/asker/check_input.rb
asker-tool-2.3.4 lib/asker/check_input.rb
asker-tool-2.3.3 lib/asker/check_input.rb
asker-tool-2.3.2 lib/asker/check_input.rb
asker-tool-2.3.1 lib/asker/check_input.rb
asker-tool-2.3.0 lib/asker/check_input.rb
asker-tool-2.2.5 lib/asker/check_input.rb