Class: PackageValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/cmd/validate.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(facts, flavor = nil) ⇒ PackageValidator

Returns a new instance of PackageValidator.



47
48
49
50
51
52
53
54
55
56
# File 'lib/cmd/validate.rb', line 47

def initialize facts, flavor=nil
  @facts = facts
  @errors = []
  if @facts.has_flavors? && flavor.nil?
    raise RuntimeError.new(FlavorArgumentMsg % @facts.flavors.join("\n- "))
  elsif @facts.has_flavors? && flavor != false
    @facts.flavor! flavor
  end
  validate
end

Class Attribute Details

.validationsObject

Returns the value of attribute validations.



34
35
36
# File 'lib/cmd/validate.rb', line 34

def validations
  @validations
end

Instance Attribute Details

#errorsObject

Returns the value of attribute errors.



31
32
33
# File 'lib/cmd/validate.rb', line 31

def errors
  @errors
end

Class Method Details

.validate(name, method_name) ⇒ Object



35
36
37
38
# File 'lib/cmd/validate.rb', line 35

def validate name, method_name
  @validations ||= []
  @validations << [name, method_name]
end

Instance Method Details

#check_hooks(hook_cmd) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/cmd/validate.rb', line 58

def check_hooks hook_cmd
  hook_cmd.map do |cmd|
    if !File.exist? cmd
       "#{cmd} cannot be found"
    elsif !File.executable? cmd
      "#{cmd} is not executable"
    end
  end.compact
end

#config_files_presentObject



106
107
108
109
110
111
112
113
114
# File 'lib/cmd/validate.rb', line 106

def config_files_present
  if @facts.config_files.empty?
    ["#{Tty.red}missing#{Tty.reset}", ['Add config_files see manual for more information']]
  elsif @facts.config_files.any?{|f| !File.exist? f}
    ["#{Tty.red}error#{Tty.reset}", @facts.config_files.select{|f| !File.exist? f}.map{|f| "#{f.to_s.split("/").last} is missing from this package"}]
  else
    ["#{Tty.green}found#{Tty.reset}", nil]
  end
end

#has_errors?Boolean

Returns:

  • (Boolean)


122
123
124
# File 'lib/cmd/validate.rb', line 122

def has_errors?
  errors.any?{|e| !e[2].nil? }
end

#homepage_presentObject



90
91
92
93
94
95
96
# File 'lib/cmd/validate.rb', line 90

def homepage_present
  if @facts.has_key? 'homepage'
    ["#{Tty.green}found#{Tty.reset}", nil]
  else
    ["#{Tty.red}missing#{Tty.reset}", ['adding a homepage improves the credibility', 'of your package']]
  end
end

#hook_ok(config_files) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/cmd/validate.rb', line 68

def hook_ok config_files
  hook_cmd = config_files
  if hook_cmd.empty?
    ["#{Tty.green}skipped#{Tty.reset}", nil]
  else
    errors = check_hooks hook_cmd
    if errors.length > 0
      ["#{Tty.red}error#{Tty.reset}", errors]
    else
      ["#{Tty.green}ok#{Tty.reset}", nil]
    end
  end
end

#post_update_hooks_okObject



86
87
88
# File 'lib/cmd/validate.rb', line 86

def post_update_hooks_ok
  hook_ok @facts.post :update
end

#setup_okObject



82
83
84
# File 'lib/cmd/validate.rb', line 82

def setup_ok
  hook_ok @facts.setup_files
end

#validateObject



116
117
118
119
120
# File 'lib/cmd/validate.rb', line 116

def validate
  self.class.validations.each do |validation|
    errors << [validation[0], *send(validation[1])]
  end
end

#version_presentObject



98
99
100
101
102
103
104
# File 'lib/cmd/validate.rb', line 98

def version_present
  if @facts.has_key? 'version'
    ["#{Tty.green}found#{Tty.reset}", nil]
  else
    ["#{Tty.red}missing#{Tty.reset}", ['adding a version to the manifest improves', 'a future update experince']]
  end
end