Class: PackageValidator
- Inherits:
-
Object
- Object
- PackageValidator
- Defined in:
- lib/cmd/validate.rb
Class Attribute Summary collapse
-
.validations ⇒ Object
Returns the value of attribute validations.
Instance Attribute Summary collapse
-
#errors ⇒ Object
Returns the value of attribute errors.
Class Method Summary collapse
Instance Method Summary collapse
- #check_hooks(hook_cmd) ⇒ Object
- #config_files_present ⇒ Object
- #has_errors? ⇒ Boolean
- #homepage_present ⇒ Object
- #hook_ok(config_files) ⇒ Object
-
#initialize(facts, flavor = nil) ⇒ PackageValidator
constructor
A new instance of PackageValidator.
- #post_update_hooks_ok ⇒ Object
- #setup_ok ⇒ Object
- #validate ⇒ Object
- #version_present ⇒ Object
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
.validations ⇒ Object
Returns the value of attribute validations.
34 35 36 |
# File 'lib/cmd/validate.rb', line 34 def validations @validations end |
Instance Attribute Details
#errors ⇒ Object
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_present ⇒ Object
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
122 123 124 |
# File 'lib/cmd/validate.rb', line 122 def has_errors? errors.any?{|e| !e[2].nil? } end |
#homepage_present ⇒ Object
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_ok ⇒ Object
86 87 88 |
# File 'lib/cmd/validate.rb', line 86 def post_update_hooks_ok hook_ok @facts.post :update end |
#setup_ok ⇒ Object
82 83 84 |
# File 'lib/cmd/validate.rb', line 82 def setup_ok hook_ok @facts.setup_files end |
#validate ⇒ Object
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_present ⇒ Object
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 |