Class: Tay::SpecificationValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/tay/specification_validator.rb

Overview

Takes a Tay::Specification and does sanity checks for missing required fields. It also looks for common mistakes and mutually exclusive flags.

If the output directory is supplied (referencing the compiled extension), the existence of files referenced in the specification will also be checked for their presence.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(specification, output_directory = nil) ⇒ SpecificationValidator

Returns a new instance of SpecificationValidator.



34
35
36
37
38
39
# File 'lib/tay/specification_validator.rb', line 34

def initialize(specification, output_directory = nil)
  @spec = specification
  @out = output_directory ? Pathname.new(output_directory) : nil
  @errors = []
  @warnings = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



23
24
25
# File 'lib/tay/specification_validator.rb', line 23

def errors
  @errors
end

#on_messageObject

A proc object that will be called on each message with the type and msg



20
21
22
# File 'lib/tay/specification_validator.rb', line 20

def on_message
  @on_message
end

#specObject (readonly)

Pointer to the relevant Tay::Specification



12
13
14
# File 'lib/tay/specification_validator.rb', line 12

def spec
  @spec
end

#violentObject

If true (default) throw an exception on error



16
17
18
# File 'lib/tay/specification_validator.rb', line 16

def violent
  @violent
end

#warningsObject (readonly)

Returns the value of attribute warnings.



22
23
24
# File 'lib/tay/specification_validator.rb', line 22

def warnings
  @warnings
end

Class Method Details

.validate(specification, output_directory = nil) ⇒ Object

Convenience method to validate a specification. Creates a validator and runs it. Will throw an exception if invalid.



28
29
30
31
32
# File 'lib/tay/specification_validator.rb', line 28

def self.validate(specification, output_directory = nil)
  validator = SpecificationValidator.new(specification, output_directory)
  validator.violent = true
  validator.validate!
end

Instance Method Details

#validate!Object

Facade method to call the private validation methods. Will return true if there were no warnings or errors



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/tay/specification_validator.rb', line 44

def validate!
  validate_name
  validate_version
  validate_icons
  validate_description

  check_for_browser_ui_collisions

  check_file_presence if @out

  @warnings.empty? && @errors.empty?
end