Module: Roles::DataMapper::ClassMethods

Defined in:
lib/roles_data_mapper/base.rb

Constant Summary collapse

MAP =
{
  :admin_flag   => "property :admin_flag,   ::DataMapper::Property::Flag[:admin, :guest]",
  :roles_mask   => "property :roles_mask,   Integer, :default => 0",
  :role_string  => "property :role_string,  String",
  :roles_string => "property :roles_string, String"
}

Instance Method Summary collapse

Instance Method Details

#strategy(name, options = {}) ⇒ Object

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/roles_data_mapper/base.rb', line 36

def strategy name, options={}
  strategy_name = name.to_sym
  raise ArgumentError, "Unknown role strategy #{strategy_name}" if !valid_strategies.include? strategy_name

  use_roles_strategy strategy_name

  set_role_class(strategy_name, options) if strategies_with_role_class.include? strategy_name
          
  if options == :default && MAP[name]
    instance_eval MAP[name] 
  end
  
  set_role_strategy name, options
end

#valid_multi_strategiesObject



28
29
30
# File 'lib/roles_data_mapper/base.rb', line 28

def valid_multi_strategies
  [:many_roles, :roles_mask]
end

#valid_single_strategiesObject



24
25
26
# File 'lib/roles_data_mapper/base.rb', line 24

def valid_single_strategies
  [:admin_flag, :one_role, :role_string]
end

#valid_strategiesObject



32
33
34
# File 'lib/roles_data_mapper/base.rb', line 32

def valid_strategies
  valid_single_strategies + valid_multi_strategies
end