Sha256: 2990859c4ea46f121fdab278651a47f673eefe40a232b11a43f86064b57a6120

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
recurso-0.6.1 lib/recurso/config.rb