Sha256: 6f8a90abab40fc21c8a4b12c9fd54ee6cb2ce4fa4d0a6558ffe41232440d45f0

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

module CanTango
  module PermissionEngine
    module Loader 
      class Categories < Base
        attr_reader :file_name, :categories

        def initialize file = nil
          begin
            @file_name = file || categories_config_file
            yml_content.each do |key, value|
              parser.parse(categories, key, value)
            end

          rescue RuntimeError => e
            raise "CanTango::Categories::Loader Error: The categories for the file #{file_name} could not be loaded - cause was #{e}"
          end
        end

        def category name
          categories.category(name).subjects
        end

        def categories
          @categories ||= CanTango.config.categories
        end

        def parser
          @parser ||= CanTango::PermissionEngine::Parser::Categories.new
        end

        def load_categories name = nil
          name ||= categories_config_file
          CanTango::Categories::Loader.new name
        end

        def categories_config_file
          get_config_file 'categories'
        end

        def get_config_file name
          File.join(config_path, "#{name}.yml")
        end

        def config_path
          CanTango.config.permissions.config_path
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cantango-0.8.0 lib/cantango/permission_engine/loader/categories.rb