Class: ERDB::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/erdb/utils.rb

Class Method Summary collapse

Class Method Details

.display_output(data, provider) ⇒ void

This method returns an undefined value.

Display the ER Diagram required data.

Parameters:

  • data (String)
  • provider (String)


10
11
12
13
14
15
# File 'lib/erdb/utils.rb', line 10

def display_output(data, provider)
  puts "### Copy following output to #{provider} if unexpected error happen ###"
  puts "### Start of output ###\n\n"
  puts data
  puts "\n### End of output ###"
end

.is_mac?Boolean

Check if the current OS is macOS.

Returns:

  • (Boolean)


20
21
22
# File 'lib/erdb/utils.rb', line 20

def is_mac?
  RbConfig::CONFIG["host_os"] =~ /darwin|mac os/
end

.to_many_to_many(relations) ⇒ Array

Convert the relations to ER Diagram format.

Examples:

[
  {
    from: {
      table: "users",
      column: "id"
    },
      to: {
        table: "posts",
        column: "user_id"
    }
  }
]
# => ["users.id", "posts.user_id"]

Parameters:

  • relations (Array)

Returns:

  • (Array)


42
43
44
45
46
# File 'lib/erdb/utils.rb', line 42

def to_many_to_many(relations)
  relations.map do |relation|
    "#{relation[:to][:table]}.#{relation[:to][:column]}"
  end.uniq
end