class Yml2erd::SchemaStructure

Attributes

structure_yml[RW]
table_names[RW]

Public Class Methods

new(yml) click to toggle source
# File lib/yml2erd/schema_structure.rb, line 6
def initialize(yml)
  @structure_yml = yml
  @table_names = table_names
end

Public Instance Methods

belongs(table_name) click to toggle source

returns an array like below

'user_auths', 'companies'
# File lib/yml2erd/schema_structure.rb, line 25
def belongs(table_name)
  relation(table_name)['belongs_to']
end
columns(table_name) click to toggle source

returns an array like below

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

# File lib/yml2erd/schema_structure.rb, line 41
def columns(table_name)
  structure_yml[table_name]['columns']
end
comment(table_name) click to toggle source

returns a string like below

> “This is users table”

# File lib/yml2erd/schema_structure.rb, line 59
def comment(table_name)
  structure_yml[table_name]['comment']
end
index(table_name) click to toggle source

returns an array like below

> [“email”]

# File lib/yml2erd/schema_structure.rb, line 47
def index(table_name)
  structure_yml[table_name]['index']
end
relation(table_name) click to toggle source

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

# File lib/yml2erd/schema_structure.rb, line 19
def relation(table_name)
  relations = structure_yml[table_name]['relations']
end
relations() click to toggle source
# File lib/yml2erd/schema_structure.rb, line 29
def relations
  table_names.map { |table_name| relation(table_name) }
end
shared_columns() click to toggle source

returns a hash like below

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

# File lib/yml2erd/schema_structure.rb, line 53
def shared_columns
  structure_yml['shared_columns']
end
table(table_name) click to toggle source

returns a hash like below

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

# File lib/yml2erd/schema_structure.rb, line 35
def table(table_name)
  structure_yml[table_name]
end