module Recurso class Config include Singleton DEFAULT_IDENTITY_FOREIGN_KEY = :identity_id DEFAULT_PERMISSION_CLASS_NAME = 'Permission' attr_accessor :levels_for_action, :actions_for_default, :levels, :default_level, :identity_foreign_key, :permission_class_name, :default_permission_class_name, :global_relations def initialize @levels_for_action = { view: [:admin, :editor, :viewer], modify: [:admin, :editor], administer: [:admin], } @actions_for_default = { open: [:view, :modify], closed: [:view], secret: [], } @levels = [:member, :admin, :editor, :viewer] @default_level = :member @identity_foreign_key = DEFAULT_IDENTITY_FOREIGN_KEY @permission_class_name = DEFAULT_PERMISSION_CLASS_NAME @global_relations = [] end def model_specific(value, model) if value.respond_to?(:call) value.call(model) else value end end def identity_foreign_key_for(model) model_specific(identity_foreign_key, model) || DEFAULT_IDENTITY_FOREIGN_KEY end def permission_class_name_for(identity_model) model_specific(permission_class_name, identity_model) || DEFAULT_PERMISSION_CLASS_NAME end end end