Class: Steep::Signature::Validator
- Inherits:
-
Object
- Object
- Steep::Signature::Validator
- Defined in:
- lib/steep/signature/validator.rb
Constant Summary collapse
- Location =
Ruby::Signature::Location
- Declarations =
Ruby::Signature::AST::Declarations
Instance Attribute Summary collapse
-
#checker ⇒ Object
readonly
Returns the value of attribute checker.
Instance Method Summary collapse
- #builder ⇒ Object
- #each_error(&block) ⇒ Object
- #env ⇒ Object
- #factory ⇒ Object
- #has_error? ⇒ Boolean
-
#initialize(checker:) ⇒ Validator
constructor
A new instance of Validator.
- #no_error? ⇒ Boolean
- #rescue_validation_errors ⇒ Object
- #validate ⇒ Object
- #validate_alias ⇒ Object
- #validate_const ⇒ Object
- #validate_decl ⇒ Object
- #validate_global ⇒ Object
- #validate_one_decl(name, decl) ⇒ Object
Constructor Details
#initialize(checker:) ⇒ Validator
Returns a new instance of Validator.
9 10 11 12 |
# File 'lib/steep/signature/validator.rb', line 9 def initialize(checker:) @checker = checker @errors = [] end |
Instance Attribute Details
#checker ⇒ Object (readonly)
Returns the value of attribute checker.
7 8 9 |
# File 'lib/steep/signature/validator.rb', line 7 def checker @checker end |
Instance Method Details
#builder ⇒ Object
34 35 36 |
# File 'lib/steep/signature/validator.rb', line 34 def builder checker.factory.definition_builder end |
#each_error(&block) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/steep/signature/validator.rb', line 22 def each_error(&block) if block_given? @errors.each(&block) else enum_for :each_error end end |
#env ⇒ Object
30 31 32 |
# File 'lib/steep/signature/validator.rb', line 30 def env checker.factory.env end |
#factory ⇒ Object
38 39 40 |
# File 'lib/steep/signature/validator.rb', line 38 def factory checker.factory end |
#has_error? ⇒ Boolean
14 15 16 |
# File 'lib/steep/signature/validator.rb', line 14 def has_error? !no_error? end |
#no_error? ⇒ Boolean
18 19 20 |
# File 'lib/steep/signature/validator.rb', line 18 def no_error? @errors.empty? end |
#rescue_validation_errors ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/steep/signature/validator.rb', line 105 def rescue_validation_errors yield rescue Ruby::Signature::InvalidTypeApplicationError => exn @errors << Errors::InvalidTypeApplicationError.new( name: factory.type_name(exn.type_name), args: exn.args.map {|ty| factory.type(ty) }, params: exn.params.each.map(&:name), location: exn.location ) rescue Ruby::Signature::NoTypeFoundError => exn @errors << Errors::UnknownTypeNameError.new( name: factory.type_name(exn.type_name), location: exn.location ) end |
#validate ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/steep/signature/validator.rb', line 42 def validate @errors = [] validate_decl validate_const validate_global end |
#validate_alias ⇒ Object
96 97 98 99 100 101 102 103 |
# File 'lib/steep/signature/validator.rb', line 96 def validate_alias env.each_alias do |name, decl| rescue_validation_errors do Steep.logger.info "#{Location.to_string decl.location}:\tValidating alias `#{name}`..." env.validate(decl.type, namespace: name.namespace) end end end |
#validate_const ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/steep/signature/validator.rb', line 78 def validate_const env.each_constant do |name, decl| rescue_validation_errors do Steep.logger.info "#{Location.to_string decl.location}:\tValidating constant `#{name}`..." env.validate(decl.type, namespace: name.namespace) end end end |
#validate_decl ⇒ Object
72 73 74 75 76 |
# File 'lib/steep/signature/validator.rb', line 72 def validate_decl env.each_decl do |name, decl| validate_one_decl name, decl end end |
#validate_global ⇒ Object
87 88 89 90 91 92 93 94 |
# File 'lib/steep/signature/validator.rb', line 87 def validate_global env.each_global do |name, decl| rescue_validation_errors do Steep.logger.info "#{Location.to_string decl.location}:\tValidating global `#{name}`..." env.validate(decl.type, namespace: Ruby::Signature::Namespace.root) end end end |
#validate_one_decl(name, decl) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/steep/signature/validator.rb', line 50 def validate_one_decl(name, decl) case decl when Declarations::Class rescue_validation_errors do Steep.logger.info "#{Location.to_string decl.location}:\tValidating class definition `#{name}`..." builder.build_instance(decl.name.absolute!).each_type do |type| env.validate type, namespace: Ruby::Signature::Namespace.root end builder.build_singleton(decl.name.absolute!).each_type do |type| env.validate type, namespace: Ruby::Signature::Namespace.root end end when Declarations::Interface rescue_validation_errors do Steep.logger.info "#{Location.to_string decl.location}:\tValidating interface `#{name}`..." builder.build_interface(decl.name.absolute!, decl).each_type do |type| env.validate type, namespace: Ruby::Signature::Namespace.root end end end end |