Class: Yml2erd::SchemaStructure
- Inherits:
-
Object
- Object
- Yml2erd::SchemaStructure
- Defined in:
- lib/yml2erd/schema_structure.rb,
lib/yml2erd/schema_structure/validator.rb
Defined Under Namespace
Classes: Validator
Instance Attribute Summary collapse
-
#structure_yml ⇒ Object
Returns the value of attribute structure_yml.
-
#table_names ⇒ Object
returns an array which has table_names like bellow => [“users”, “user_auths”, “posts”, “companies”].
Instance Method Summary collapse
-
#belongs(table_name) ⇒ Object
returns an array like below [‘user_auths’, ‘companies’].
-
#columns(table_name) ⇒ Object
returns an array like below => [“name”=>“string”, “email”=>“string”].
-
#index(table_name) ⇒ Object
returns an array like below => [“email”].
-
#initialize(yml) ⇒ SchemaStructure
constructor
A new instance of SchemaStructure.
-
#relation(table_name) ⇒ Object
returns a hash like below { belongs_to: [‘user_auths’, ‘companies’], has_many: [‘posts’] }.
- #relations ⇒ Object
-
#shared_columns ⇒ Object
returns a hash like below => { “id”=>“integer”, “created_at”=>“datetime”, “updated_at”=>“datetime” }.
-
#table(table_name) ⇒ Object
returns a hash like below => “columns”=>[{“name”=>“string”, “email”=>“string”], “relations”=>“companies”], “has_many“=>}.
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_yml ⇒ Object
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_names ⇒ Object
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 |
#relations ⇒ Object
29 30 31 |
# File 'lib/yml2erd/schema_structure.rb', line 29 def relations table_names.map { |table_name| relation(table_name) } end |
#shared_columns ⇒ Object
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 |