Exception: LearnError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/learn-tool/learn-error.rb

Constant Summary collapse

ESCAPES =
{ :green  => "\033[32m",
:yellow => "\033[33m",
:red    => "\033[31m",
:reset  => "\033[0m" }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLearnError

Returns a new instance of LearnError.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/learn-tool/learn-error.rb', line 13

def initialize
  @yaml_error = {present_dotlearn: false, valid_yaml: false, valid_whitespace: false, attributes: false}
  @readme_error = {present_readme: false, valid_readme: false}
  @license_error = {present_license: false, valid_license: false}
  @contributing_error = {present_contributing: false, valid_contributing: false}

  @correct_yaml_content = {message: ".learn file must have 'languages' key", color: :red}

  @valid_yaml = {message: "invalid yaml", color: :red}
  @valid_license = {message: "invalid or missing license content", color: :yellow}
  @valid_readme = {message: [], color: :red}
  @valid_contributing = {message: "invalid or missing contributing content", color: :yellow}

  @present_learn = {message: "missing .learn file", color: :red}
  @present_license = {message: "missing LICENSE.md", color: :red}
  @present_readme = {message: "missing README.md", color: :red}
  @present_contributing = {message: "missing CONTRIBUTING.md", color: :red}

end

Instance Attribute Details

#contributing_errorObject

Returns the value of attribute contributing_error.



2
3
4
# File 'lib/learn-tool/learn-error.rb', line 2

def contributing_error
  @contributing_error
end

#correct_yaml_contentObject

Returns the value of attribute correct_yaml_content.



2
3
4
# File 'lib/learn-tool/learn-error.rb', line 2

def correct_yaml_content
  @correct_yaml_content
end

#filepathObject

Returns the value of attribute filepath.



2
3
4
# File 'lib/learn-tool/learn-error.rb', line 2

def filepath
  @filepath
end

#license_errorObject

Returns the value of attribute license_error.



2
3
4
# File 'lib/learn-tool/learn-error.rb', line 2

def license_error
  @license_error
end

#present_contributingObject

Returns the value of attribute present_contributing.



2
3
4
# File 'lib/learn-tool/learn-error.rb', line 2

def present_contributing
  @present_contributing
end

#present_learnObject

Returns the value of attribute present_learn.



2
3
4
# File 'lib/learn-tool/learn-error.rb', line 2

def present_learn
  @present_learn
end

#present_licenseObject

Returns the value of attribute present_license.



2
3
4
# File 'lib/learn-tool/learn-error.rb', line 2

def present_license
  @present_license
end

#present_readmeObject

Returns the value of attribute present_readme.



2
3
4
# File 'lib/learn-tool/learn-error.rb', line 2

def present_readme
  @present_readme
end

#readme_errorObject

Returns the value of attribute readme_error.



2
3
4
# File 'lib/learn-tool/learn-error.rb', line 2

def readme_error
  @readme_error
end

#valid_contributingObject

Returns the value of attribute valid_contributing.



2
3
4
# File 'lib/learn-tool/learn-error.rb', line 2

def valid_contributing
  @valid_contributing
end

#valid_licenseObject

Returns the value of attribute valid_license.



2
3
4
# File 'lib/learn-tool/learn-error.rb', line 2

def valid_license
  @valid_license
end

#valid_readmeObject

Returns the value of attribute valid_readme.



2
3
4
# File 'lib/learn-tool/learn-error.rb', line 2

def valid_readme
  @valid_readme
end

#valid_yamlObject

Returns the value of attribute valid_yaml.



2
3
4
# File 'lib/learn-tool/learn-error.rb', line 2

def valid_yaml
  @valid_yaml
end

#yaml_errorObject

Returns the value of attribute yaml_error.



2
3
4
# File 'lib/learn-tool/learn-error.rb', line 2

def yaml_error
  @yaml_error
end

Instance Method Details

#emit(opts = {}) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/learn-tool/learn-error.rb', line 33

def emit(opts={})
  color   = opts[:color]
  message = opts[:message]
  print ESCAPES[color]
  print message
  print ESCAPES[:reset]
  print "\n"
end

#result_messageObject



52
53
54
# File 'lib/learn-tool/learn-error.rb', line 52

def result_message
  [present_learn, valid_yaml, correct_yaml_content, present_license, valid_license, present_readme, valid_readme, present_contributing, valid_contributing ]
end

#result_outputObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/learn-tool/learn-error.rb', line 57

def result_output
  result_message.each do |result|
    if result[:message].is_a?(Array)
      result[:message].each do |result_message| 
        emit({message: result_message, color: result[:color]})
      end
    else
      emit(result)
    end
  end
end

#total_errorsObject



42
43
44
45
46
47
48
49
50
# File 'lib/learn-tool/learn-error.rb', line 42

def total_errors
  {
    dot_learn: yaml_error,
    license: license_error,
    readme: readme_error,
    contributing: contributing_error
  }
  
end