Class: AnnotateRb::ModelAnnotator::AnnotationDecider
- Inherits:
-
Object
- Object
- AnnotateRb::ModelAnnotator::AnnotationDecider
- Defined in:
- lib/annotate_rb/model_annotator/annotation_decider.rb
Overview
Class that encapsulates the logic to decide whether to annotate a model file and its related files or not.
Constant Summary collapse
- SKIP_ANNOTATION_PREFIX =
'# -\*- SkipSchemaAnnotations'
Instance Method Summary collapse
- #annotate? ⇒ Boolean
-
#initialize(file, options) ⇒ AnnotationDecider
constructor
A new instance of AnnotationDecider.
Constructor Details
#initialize(file, options) ⇒ AnnotationDecider
Returns a new instance of AnnotationDecider.
9 10 11 12 |
# File 'lib/annotate_rb/model_annotator/annotation_decider.rb', line 9 def initialize(file, ) @file = file = end |
Instance Method Details
#annotate? ⇒ Boolean
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/annotate_rb/model_annotator/annotation_decider.rb', line 14 def annotate? return false if file_contains_skip_annotation begin klass = ModelClassGetter.call(@file, ) klass_is_a_class = klass.is_a?(Class) klass_inherits_active_record_base = klass < ActiveRecord::Base klass_is_not_abstract = klass.respond_to?(:abstract_class) && !klass.abstract_class? klass_table_exists = klass.respond_to?(:abstract_class) && klass.table_exists? not_sure_this_conditional = (![:exclude_sti_subclasses] || !(klass.superclass < ActiveRecord::Base && klass.table_name == klass.superclass.table_name)) annotate_conditions = [ klass_is_a_class, klass_inherits_active_record_base, not_sure_this_conditional, klass_is_not_abstract, klass_table_exists ] to_annotate = annotate_conditions.all? return to_annotate rescue BadModelFileError => e unless [:ignore_unknown_models] warn "Unable to process #{@file}: #{e.message}" warn "\t" + e.backtrace.join("\n\t") if [:trace] end rescue => e warn "Unable to process #{@file}: #{e.message}" warn "\t" + e.backtrace.join("\n\t") if [:trace] end false end |