class Yml2erd::SchemaStructure::Validator
Constants
- RELATIONS_KEY
Attributes
ss[R]
Public Class Methods
new(schema_structure)
click to toggle source
# File lib/yml2erd/schema_structure/validator.rb, line 11 def initialize(schema_structure) @ss = schema_structure end
Public Instance Methods
validate()
click to toggle source
# File lib/yml2erd/schema_structure/validator.rb, line 15 def validate # relations columns keyname end
Private Instance Methods
columns()
click to toggle source
columns must be an array
# File lib/yml2erd/schema_structure/validator.rb, line 29 def columns ss.table_names.each do |table_name| raise InvalidYmlStructureError, 'columns must be an array' unless ss.columns(table_name).class == Array end end
correct_relation_key?(table_name)
click to toggle source
# File lib/yml2erd/schema_structure/validator.rb, line 57 def correct_relation_key?(table_name) ss.relation(table_name).keys.map { |key| RELATIONS_KEY.include?(key) }.all? end
keyname()
click to toggle source
yml structure is just like below “` <table_name>:
columns: - <column_name>: <column_type> relations: belongs_to: - <table_name> has_many: - <table_name> index: - <column_name>
“` belongs_to or has_many is not necessary
# File lib/yml2erd/schema_structure/validator.rb, line 49 def keyname ss.table_names.each do |table_name| if ss.columns(table_name).nil? && ss.relation(table_name).nil? raise InvalidKeyNameError, 'you must use correct keyname' end end end
relations()
click to toggle source
check to match or not a table name among relations
# File lib/yml2erd/schema_structure/validator.rb, line 24 def relations raise InvalidYmlStructureError end