Sha256: e9b12cca7609cb2455675b50deaae5d2b68ecf38119887ed41ee3f4f9e8258ea

Contents?: true

Size: 800 Bytes

Versions: 4

Compression:

Stored size: 800 Bytes

Contents

require 'singleton'
require 'yaml'

module StrongActions
  class Config
    include Singleton

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

    def config_files
      @config_files
    end

    def config_files=(files)
      @config_files = ([] << files).flatten
    end

    def roles
      definitions.keys
    end

    def role_definition(role)
      definitions[role]
    end

    private

    def definitions
      if @acl.nil? or Rails.env.development?
        @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
      @acl
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
strong_actions-0.0.8 lib/strong_actions/config.rb
strong_actions-0.0.7 lib/strong_actions/config.rb
strong_actions-0.0.6 lib/strong_actions/config.rb
strong_actions-0.0.5 lib/strong_actions/config.rb