Sha256: a8f33ae1b67a54482e8be010aeaa07621355400a0822736258442ef5686ae966

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 KB

Contents

require "yaml"

module SCSSBeautifier
  class Config
    DEFAULT = File.realpath(File.join(File.dirname(__FILE__), "..", "..", "data", "default_config.yml")).freeze

    def initialize(config_location)
      @config = parse_config(config_location.to_s)
    end

    def parse_config(config_location)
      config_contents = read_config(config_location)
      YAML.load(config_contents)
    end

    def formatters
      enabled_formatters = []
      @config["formatters"].each do |formatter, options|
        if options["enabled"]
          klass = SCSSBeautifier::Formatters.const_get(formatter.split("_").map(&:capitalize).join)
          enabled_formatters << klass.new(options)
        end
      end
      enabled_formatters
    end

    def options
      options_with_key_symbols = {}
      @config["options"].each do |k, v|
        options_with_key_symbols[:"#{k}"] = v
      end
      options_with_key_symbols
    end

    private

    def read_config(config_location)
      location = File.exists?(config_location) ? config_location : DEFAULT
      File.read(location)
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scss_beautifier-0.1.19 lib/scss_beautifier/config.rb