Sha256: 854927651a3fa0b2f0ec4d6ee29efe1096e1ffe490fe6d291a01eeb100564bcc

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

require 'yaml'

module Cas
  class Config

    def initialize(filename: nil)
      @filename = filename
    end

    def uploads
      uploads = config["uploads"] || {}

      # TODO - clarify what this is and how to configure
      {
        cache_directory_prefix: uploads["cache_directory_prefix"] || "cache",
        store_directory_prefix: uploads["store_directory_prefix"] || "store"
      }
    end

    private

    def read_file
      begin
        @file ||= YAML.safe_load_file(filename, aliases: true)
      rescue NoMethodError, ArgumentError
        @file ||= YAML.load_file(filename)
      end
    end

    def filename
      @filename ||= begin
                      if File.exists?(Cas::CONFIG_PATH)
                        Cas::CONFIG_PATH
                      elsif ENV['RAILS_ENV'] == 'test'
                        "spec/fixtures/cas.yml"
                      else
                        raise "cas.yml file is not defined."
                      end
      end
    end

    def config
      read_file["config"] || {}
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cas-cms-1.0.0.alpha2 lib/cas/config.rb
cas-cms-1.0.0.alpha1 lib/cas/config.rb