Sha256: f3309964d55650f90737e623e960eb3dc0beb588dc98dda5b2ced9f98dee1afa

Contents?: true

Size: 1.36 KB

Versions: 21

Compression:

Stored size: 1.36 KB

Contents

module Typus
  module Configuration

    # Read configuration from <tt>config/typus/**/*.yml</tt>.
    def self.config!
      application = Dir[File.join(Typus.config_folder, "**", "*.yml").to_s]
      plugins = Dir[File.join("vendor", "plugins", "*", "config", "typus", "*.yml").to_s]
      files = (application + plugins).reject { |f| f.include?("_roles.yml") }

      @@config = {}

      files.each do |file|
        if data = YAML::load_file(file)
          @@config.merge!(data)
        end
      end

      @@config
    end

    mattr_accessor :config

    # Read roles from files <tt>config/typus/**/*_roles.yml</tt>.
    def self.roles!
      application = Dir[File.join(Typus.config_folder, "**", "*_roles.yml").to_s]
      plugins = Dir[File.join("vendor", "plugins", "*", "config", "typus", "*_roles.yml").to_s]
      files = (application + plugins).sort

      @@roles = {}

      files.each do |file|
        if data = YAML::load_file(file)
          data.compact.each do |key, value|
            @@roles[key] ? @@roles[key].merge!(value) : (@@roles[key] = value)
          end
        end
      end

      @@roles
    end

    mattr_accessor :roles

    def self.models_constantized!
      @@models_constantized = config.map { |i| i.first }.inject({}) { |result, model| result[model] = model.constantize; result }
    end

    mattr_accessor :models_constantized

  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
typus-3.0.12 lib/typus/configuration.rb
typus-3.0.11 lib/typus/configuration.rb
typus-3.0.11.rc5 lib/typus/configuration.rb
typus-3.1.0.rc11 lib/typus/configuration.rb
typus-3.1.0.rc10 lib/typus/configuration.rb
typus-3.0.11.rc4 lib/typus/configuration.rb
typus-3.1.0.rc9 lib/typus/configuration.rb
typus-3.0.11.rc3 lib/typus/configuration.rb
typus-3.1.0.rc8 lib/typus/configuration.rb
typus-3.1.0.rc7 lib/typus/configuration.rb
typus-3.1.0.rc6 lib/typus/configuration.rb
typus-3.1.0.rc5 lib/typus/configuration.rb
typus-3.1.0.rc4 lib/typus/configuration.rb
typus-3.1.0.rc3 lib/typus/configuration.rb
typus-3.1.0.rc2 lib/typus/configuration.rb
typus-3.0.11.rc2 lib/typus/configuration.rb
typus-3.0.11.rc1 lib/typus/configuration.rb
typus-3.1.0.rc1 lib/typus/configuration.rb
typus-3.0.10 lib/typus/configuration.rb
typus-3.0.9 lib/typus/configuration.rb