Module: SimpleRoles::Configuration

Extended by:
Configuration
Included in:
Configuration
Defined in:
lib/simple_roles/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#strategy(st = nil) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/simple_roles/configuration.rb', line 31

def strategy st = nil
  if st
    self.strategy = st
  end

  @strategy ||= default_strategy
end

#user_modelsObject



7
8
9
# File 'lib/simple_roles/configuration.rb', line 7

def user_models
  @user_models ||= []
end

Instance Method Details

#available_strategiesObject



45
46
47
# File 'lib/simple_roles/configuration.rb', line 45

def available_strategies
  strategies.keys
end

#default_rolesObject



27
28
29
# File 'lib/simple_roles/configuration.rb', line 27

def default_roles
  [:user, :admin]
end

#strategiesObject



53
54
55
56
57
58
# File 'lib/simple_roles/configuration.rb', line 53

def strategies
  {
    :one => SimpleRoles::One,
    :many => SimpleRoles::Many
  }
end

#strategy_class(_strategy = nil) ⇒ Object



49
50
51
# File 'lib/simple_roles/configuration.rb', line 49

def strategy_class _strategy = nil
  strategies[_strategy || strategy]
end

#valid_roles(*vr) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/simple_roles/configuration.rb', line 11

def valid_roles *vr
  if vr.any?
    self.valid_roles = vr.flatten
  end

  @valid_roles ||= default_roles
end

#valid_roles=(vr) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/simple_roles/configuration.rb', line 19

def valid_roles= vr
  check_roles(vr)

  @valid_roles = vr

  distribute_methods
end