Module: Validatable
- Included in:
- Music::Transcription::Meter, Music::Transcription::Note, Music::Transcription::NoteScore, Music::Transcription::Part, Music::Transcription::Program
- Defined in:
- lib/music-transcription/validatable.rb
Overview
assumes that @checks is defined as an array of no-arg lambdas, each lambda raising an error (with useful msg) when check fails
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #check_methods ⇒ Object
- #invalid? ⇒ Boolean
- #valid? ⇒ Boolean
- #validatables ⇒ Object
- #validate ⇒ Object
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'lib/music-transcription/validatable.rb', line 4 def errors @errors end |
Instance Method Details
#check_methods ⇒ Object
6 |
# File 'lib/music-transcription/validatable.rb', line 6 def check_methods; []; end |
#invalid? ⇒ Boolean
35 36 37 |
# File 'lib/music-transcription/validatable.rb', line 35 def invalid? !self.valid? end |
#valid? ⇒ Boolean
30 31 32 33 |
# File 'lib/music-transcription/validatable.rb', line 30 def valid? self.validate @errors.empty? end |
#validatables ⇒ Object
7 |
# File 'lib/music-transcription/validatable.rb', line 7 def validatables; []; end |
#validate ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/music-transcription/validatable.rb', line 9 def validate @errors = [] check_methods.each do |check_method| begin send(check_method) rescue StandardError => e @errors.push e end end validatables.each do |v| if v.respond_to?(:validate) @errors += v.validate end end return @errors end |