Class: Yml2erd::SchemaStructure

Inherits:
Object
  • Object
show all
Defined in:
lib/yml2erd/schema_structure.rb,
lib/yml2erd/schema_structure/validator.rb

Defined Under Namespace

Classes: Validator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(yml) ⇒ SchemaStructure

Returns a new instance of SchemaStructure.



6
7
8
9
# File 'lib/yml2erd/schema_structure.rb', line 6

def initialize(yml)
  @structure_yml = yml
  @table_names = table_names
end

Instance Attribute Details

#structure_ymlObject

Returns the value of attribute structure_yml.



4
5
6
# File 'lib/yml2erd/schema_structure.rb', line 4

def structure_yml
  @structure_yml
end

#table_namesObject

returns an array which has table_names like bellow

> [“users”, “user_auths”, “posts”, “companies”]



13
14
15
# File 'lib/yml2erd/schema_structure.rb', line 13

def table_names
  @table_names
end

Instance Method Details

#columns(table_name) ⇒ Object

returns an array like below

> [“name”=>“string”, “email”=>“string”]



36
37
38
# File 'lib/yml2erd/schema_structure.rb', line 36

def columns(table_name)
  structure_yml[table_name]['columns']
end

#index(table_name) ⇒ Object

returns an array like below

> [“email”]



42
43
44
# File 'lib/yml2erd/schema_structure.rb', line 42

def index(table_name)
  structure_yml[table_name]['index']
end

#relation(table_name) ⇒ Object

returns a hash like below { users: { belongs_to: [‘user_auths’, ‘companies’], has_many: [‘posts’] } }



19
20
21
22
# File 'lib/yml2erd/schema_structure.rb', line 19

def relation(table_name)
  relations = structure_yml[table_name]['relations']
  # { table_name.to_sym => relations }
end

#relationsObject



24
25
26
# File 'lib/yml2erd/schema_structure.rb', line 24

def relations
  table_names.map { |table_name| relation(table_name) }
end

#table(table_name) ⇒ Object

returns a hash like below

> “columns”=>[{“name”=>“string”, “email”=>“string”], “relations”=>“companies”], “has_many“=>}



30
31
32
# File 'lib/yml2erd/schema_structure.rb', line 30

def table(table_name)
  structure_yml[table_name]
end