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.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/cmd/validate.rb', line 53 def initialize(facts, flavor = nil) @facts = facts @errors = [] if @facts.has_flavors? && flavor.nil? raise FlavorArgumentMsg % @facts.flavors.join("\n- ").to_s elsif @facts.has_flavors? && flavor != false @facts.flavor! flavor end validate end |
Class Attribute Details
.validations ⇒ Object
Returns the value of attribute validations.
39 40 41 |
# File 'lib/cmd/validate.rb', line 39 def validations @validations end |
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
36 37 38 |
# File 'lib/cmd/validate.rb', line 36 def errors @errors end |
Class Method Details
.validate(name, method_name) ⇒ Object
41 42 43 44 |
# File 'lib/cmd/validate.rb', line 41 def validate(name, method_name) @validations ||= [] @validations << [name, method_name] end |
Instance Method Details
#check_hooks(hook_cmd) ⇒ Object
65 66 67 68 69 70 71 72 73 |
# File 'lib/cmd/validate.rb', line 65 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
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/cmd/validate.rb', line 113 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.reject do |f| File.exist? f end.map { |f| "#{f.to_s.split('/').last} is missing from this package" }] else ["#{Tty.green}found#{Tty.reset}", nil] end end |
#has_errors? ⇒ Boolean
131 132 133 |
# File 'lib/cmd/validate.rb', line 131 def has_errors? errors.any? { |e| !e[2].nil? } end |
#homepage_present ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/cmd/validate.rb', line 97 def homepage_present if @facts.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
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/cmd/validate.rb', line 75 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.positive? ["#{Tty.red}error#{Tty.reset}", errors] else ["#{Tty.green}ok#{Tty.reset}", nil] end end end |
#post_update_hooks_ok ⇒ Object
93 94 95 |
# File 'lib/cmd/validate.rb', line 93 def post_update_hooks_ok hook_ok @facts.post :update end |
#setup_ok ⇒ Object
89 90 91 |
# File 'lib/cmd/validate.rb', line 89 def setup_ok hook_ok @facts.setup_files end |
#validate ⇒ Object
125 126 127 128 129 |
# File 'lib/cmd/validate.rb', line 125 def validate self.class.validations.each do |validation| errors << [validation[0], *send(validation[1])] end end |