Class: Recurso::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/recurso/config.rb

Constant Summary collapse

DEFAULT_IDENTITY_FOREIGN_KEY =
:identity_id
DEFAULT_PERMISSION_CLASS_NAME =
'Permission'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/recurso/config.rb', line 18

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

Instance Attribute Details

#actions_for_defaultObject

Returns the value of attribute actions_for_default.



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

def actions_for_default
  @actions_for_default
end

#default_levelObject

Returns the value of attribute default_level.



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

def default_level
  @default_level
end

#default_permission_class_nameObject

Returns the value of attribute default_permission_class_name.



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

def default_permission_class_name
  @default_permission_class_name
end

#global_relationsObject

Returns the value of attribute global_relations.



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

def global_relations
  @global_relations
end

#identity_foreign_keyObject

Returns the value of attribute identity_foreign_key.



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

def identity_foreign_key
  @identity_foreign_key
end

#levelsObject

Returns the value of attribute levels.



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

def levels
  @levels
end

#levels_for_actionObject

Returns the value of attribute levels_for_action.



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

def levels_for_action
  @levels_for_action
end

#permission_class_nameObject

Returns the value of attribute permission_class_name.



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

def permission_class_name
  @permission_class_name
end

Instance Method Details

#identity_foreign_key_for(model) ⇒ Object



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

def identity_foreign_key_for(model)
  model_specific(identity_foreign_key, model) || DEFAULT_IDENTITY_FOREIGN_KEY
end

#model_specific(value, model) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/recurso/config.rb', line 42

def model_specific(value, model)
  if value.respond_to?(:call)
    value.call(model)
  else
    value
  end
end

#permission_class_name_for(identity_model) ⇒ Object



54
55
56
# File 'lib/recurso/config.rb', line 54

def permission_class_name_for(identity_model)
  model_specific(permission_class_name, identity_model) || DEFAULT_PERMISSION_CLASS_NAME
end