Sha256: 1689bb493b9a8b2ab0226d7d32287c133505809560890a8dafba1b4c3f2b48b0

Contents?: true

Size: 824 Bytes

Versions: 3

Compression:

Stored size: 824 Bytes

Contents

require 'singleton'

module StrongActions
  class Config
    include Singleton

    def initialize
      @config_files = ['config/acl.yml']
      load_config_files
    end

    def config_files
      @config_files
    end

    def config_files=(files)
      config_files = files
      load_config_files
    end

    def roles
      load_config_files if Rails.env.development?
      @acl.keys
    end

    def role_definition(role)
      load_config_files if Rails.env.development?
      @acl[role]
    end

    private

    def load_config_files
      @acl = {}
      config_files.each do |config_file|
        yml = YAML.load_file(config_file)
        yml.each do |role, values|
          raise "role #{role} is already defined." if @acl.has_key?(role)
          @acl[role] = values
        end
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
strong_actions-0.0.3 lib/strong_actions/config.rb
strong_actions-0.0.2 lib/strong_actions/config.rb
strong_actions-0.0.1 lib/strong_actions/config.rb