Sha256: 548f9821e18903d6208371a80d46ba486a8281d706929d24edb13acbaaa55089

Contents?: true

Size: 1.6 KB

Versions: 2

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true
require 'closure_tree'
require 'configurations'
require 'active_record_union'

require 'monarchy/exceptions'
require 'monarchy/validators'
require 'monarchy/tasks'
require 'monarchy/engine'

require 'monarchy/acts_as_role'
require 'monarchy/acts_as_member'
require 'monarchy/acts_as_user'
require 'monarchy/acts_as_resource'
require 'monarchy/acts_as_hierarchy'

module Monarchy
  cattr_accessor :resource_classes

  def self.resource_classes
    @resource_classes ||= []
  end

  include Configurations

  configuration_defaults do |config|
    config.member_class_name = 'Monarchy::Member'
    config.role_class_name = 'Monarchy::Role'
    config.hierarchy_class_name = 'Monarchy::Hierarchy'
    config.members_access_revoke = false
    config.revoke_strategy = :revoke_member
    config.accessible_for_options.parent_access = false
    config.accessible_for_options.inherited_roles = []
  end

  not_configured do |property|
    raise Monarchy::Exceptions::ConfigNotDefined, property
  end

  def self.member_class
    Monarchy.configuration.member_class_name.safe_constantize || class_not_defined('Member')
  end

  def self.role_class
    Monarchy.configuration.role_class_name.safe_constantize || class_not_defined('Role')
  end

  def self.user_class
    Monarchy.configuration.user_class_name.safe_constantize || class_not_defined('User')
  end

  def self.hierarchy_class
    Monarchy.configuration.hierarchy_class_name.safe_constantize || class_not_defined('Hierarchy')
  end

  private

  def class_not_defined(class_name)
    raise Monarchy::Exceptions::ClassNotDefined, class_name
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
monarchy-2.1.0 lib/monarchy.rb
monarchy-2.0.8 lib/monarchy.rb