Sha256: 6c7fa1bb32ee4565c61c109d2bd89952902965c905db888aa79979165a6c8b4f

Contents?: true

Size: 1.97 KB

Versions: 1

Compression:

Stored size: 1.97 KB

Contents

module RailsERD
  class Config
    USER_WIDE_CONFIG_FILE = File.expand_path(".erdconfig", ENV["HOME"])
    CURRENT_CONFIG_FILE   = File.expand_path(".erdconfig", Dir.pwd)

    attr_reader :options

    def self.load
      new.load
    end

    def initialize
      @options = {}
    end

    def load
      load_file(USER_WIDE_CONFIG_FILE)
      load_file(CURRENT_CONFIG_FILE)

      @options
    end

    def self.font_names_based_on_os
      if use_os_x_fonts?
        { normal: "ArialMT",
          bold:   "Arial BoldMT",
          italic: "Arail ItalicMT" }
      else
        { normal: "Arial",
          bold:   "Arial Bold",
          italic: "Arail Italic" }
      end
    end

    private

    def load_file(path)
      if File.exists?(path)
        YAML.load_file(path).each do |key, value|
          key = key.to_sym
          @options[key] = normalize_value(key, value)
        end
      end
    end

    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, :orientation
        value.to_sym

      # true | false
      when :disconnected, :indirect, :inheritance, :markup, :polymorphism, :warn
        !!value

      # nil | <string>
      when :filename, :only, :exclude
        value.nil? ? nil : value.to_s

      # true | false | <string>
      when :title
        value.is_a?(String) ? value : !!value

      else
        value
      end
    end

    def self.use_os_x_fonts?
      host = RbConfig::CONFIG['host_os']

      if host.include? "darwin"
        darwin_version_array = host.split("darwin").last.split(".").map(&:to_i)

        if darwin_version_array[0] == 12 and darwin_version_array[1] >= 5
          return true
        end
      end

      false
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails-erd-1.2.0 lib/rails_erd/config.rb