class RailsERD::Config
Constants
- CURRENT_CONFIG_FILE
- USER_WIDE_CONFIG_FILE
Attributes
options[R]
Public Class Methods
font_names_based_on_os()
click to toggle source
# File lib/rails_erd/config.rb, line 29 def self.font_names_based_on_os if use_os_x_fonts? { normal: "ArialMT", bold: "Arial BoldMT", italic: "Arial ItalicMT" } else { normal: "Arial", bold: "Arial Bold", italic: "Arial Italic" } end end
load(extra_config_file=nil)
click to toggle source
# File lib/rails_erd/config.rb, line 10 def self.load(extra_config_file=nil) new.load extra_config_file end
new()
click to toggle source
# File lib/rails_erd/config.rb, line 14 def initialize @options = {} end
Private Class Methods
use_os_x_fonts?()
click to toggle source
# File lib/rails_erd/config.rb, line 95 def self.use_os_x_fonts? host = RbConfig::CONFIG['host_os'] return true if host == "darwin" if host.include? "darwin" darwin_version_array = host.split("darwin").last.split(".").map(&:to_i) return true if darwin_version_array[0] >= 13 return true if darwin_version_array[0] == 12 && darwin_version_array[1] >= 5 end false end
Public Instance Methods
load(extra_config_file=nil)
click to toggle source
# File lib/rails_erd/config.rb, line 18 def load(extra_config_file=nil) load_file(USER_WIDE_CONFIG_FILE) load_file(CURRENT_CONFIG_FILE) if extra_config_file extra_config_path = File.expand_path(extra_config_file, Dir.pwd) load_file(extra_config_path) if File.exist?(extra_config_path) end @options end
Private Instance Methods
load_file(path)
click to toggle source
# File lib/rails_erd/config.rb, line 43 def load_file(path) if File.exist?(path) YAML.load_file(path).each do |key, value| key = key.to_sym @options[key] = normalize_value(key, value) end end end
normalize_value(key, value)
click to toggle source
# File lib/rails_erd/config.rb, line 52 def normalize_value(key, value) case key # <symbol>[,<symbol>,...] | false when :attributes if value == false return value else # Comma separated string and strings in array are OK. Array(value).join(",").split(",").map { |v| v.strip.to_sym } end # <symbol> when :filetype, :notation value.to_sym # [<string>] when :only, :exclude Array(value).join(",").split(",").map { |v| v.strip } # true | false when :disconnected, :indirect, :inheritance, :markup, :polymorphism, :warn, :cluster !!value # nil | <string> when :filename, :orientation value.nil? ? nil : value.to_s # true | false | <string> when :title value.is_a?(String) ? value : !!value # nil | <Hash> when :fonts if value Hash(value).transform_keys(&:to_sym) end else value end end