Class: Permisi::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/permisi/config.rb

Defined Under Namespace

Classes: InvalidCacheStore

Constant Summary collapse

NULL_CACHE_STORE =
ActiveSupport::Cache::NullStore.new

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



12
13
14
15
# File 'lib/permisi/config.rb', line 12

def initialize
  @permissions = ::HashWithIndifferentAccess.new
  @default_permissions = ::HashWithIndifferentAccess.new
end

Instance Attribute Details

#default_permissionsObject (readonly)

Returns the value of attribute default_permissions.



9
10
11
# File 'lib/permisi/config.rb', line 9

def default_permissions
  @default_permissions
end

#mute_pre_0_1_4_warningObject

Returns the value of attribute mute_pre_0_1_4_warning.



10
11
12
# File 'lib/permisi/config.rb', line 10

def mute_pre_0_1_4_warning
  @mute_pre_0_1_4_warning
end

#permissionsObject

Returns the value of attribute permissions.



9
10
11
# File 'lib/permisi/config.rb', line 9

def permissions
  @permissions
end

Instance Method Details

#backendObject



34
35
36
# File 'lib/permisi/config.rb', line 34

def backend
  @backend || Backend::NullBackend
end

#backend=(chosen_backend) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/permisi/config.rb', line 17

def backend=(chosen_backend)
  chosen_backend = "::Permisi::Backend::#{chosen_backend.to_s.classify}".constantize if chosen_backend.is_a? Symbol

  if !mute_pre_0_1_4_warning && chosen_backend == Backend::ActiveRecord
    warn <<~MESSAGE

      WARNING: If you are upgrading from Permisi <v0.1.4, please create the following migration:
      `add_index :permisi_actor_roles, [:actor_id, :role_id], unique: true`

    MESSAGE
  end

  @backend = chosen_backend
rescue NameError
  raise Backend::InvalidBackend
end

#cache_storeObject



50
51
52
# File 'lib/permisi/config.rb', line 50

def cache_store
  @cache_store || NULL_CACHE_STORE
end

#cache_store=(cache_store) ⇒ Object

Raises:



44
45
46
47
48
# File 'lib/permisi/config.rb', line 44

def cache_store=(cache_store)
  raise InvalidCacheStore unless cache_store.respond_to?(:fetch)

  @cache_store = cache_store
end