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

#belongs(table_name) ⇒ Object

returns an array like below

‘user_auths’, ‘companies’


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

def belongs(table_name)
  relation(table_name)['belongs_to']
end

#columns(table_name) ⇒ Object

returns an array like below

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



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

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

#index(table_name) ⇒ Object

returns an array like below

> [“email”]



47
48
49
# File 'lib/yml2erd/schema_structure.rb', line 47

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

#relation(table_name) ⇒ Object

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



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

def relation(table_name)
  relations = structure_yml[table_name]['relations']
end

#relationsObject



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

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

#shared_columnsObject

returns a hash like below

> { “id”=>“integer”, “created_at”=>“datetime”, “updated_at”=>“datetime” }



53
54
55
# File 'lib/yml2erd/schema_structure.rb', line 53

def shared_columns
  structure_yml['shared_columns']
end

#table(table_name) ⇒ Object

returns a hash like below

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



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

def table(table_name)
  structure_yml[table_name]
end