Class: CanTango::Permit::Base

Inherits:
Object
  • Object
show all
Extended by:
ClassMethods
Includes:
Api::Attributes, Helpers::Debug
Defined in:
lib/cantango/permit/base.rb

Direct Known Subclasses

AccountType, Attribute, Special, User, UserType

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ClassMethods

finder, hash_key, inherited, type

Methods included from Helper::Naming

#account_name, #permit_name

Constructor Details

#initialize(ability) ⇒ Base

creates the permit



26
27
28
# File 'lib/cantango/permit/base.rb', line 26

def initialize ability
  @ability  = ability
end

Instance Attribute Details

#abilityObject (readonly)

strategy is used to control the owns strategy (see rules.rb)



15
16
17
# File 'lib/cantango/permit/base.rb', line 15

def ability
  @ability
end

#disabledObject (readonly)

strategy is used to control the owns strategy (see rules.rb)



15
16
17
# File 'lib/cantango/permit/base.rb', line 15

def disabled
  @disabled
end

#modeObject



30
31
32
# File 'lib/cantango/permit/base.rb', line 30

def mode
  @mode ||= :no_cache
end

Instance Method Details

#any(reg_exp) ⇒ Object



58
59
60
# File 'lib/cantango/permit/base.rb', line 58

def any reg_exp
  CanTango.config.models.by_reg_exp reg_exp
end

#category(label) ⇒ Object



54
55
56
# File 'lib/cantango/permit/base.rb', line 54

def category label
  CanTango.config.models.by_category label
end

#disable!Object



42
43
44
# File 'lib/cantango/permit/base.rb', line 42

def disable!
  @disabled = true
end

#disabled?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/cantango/permit/base.rb', line 46

def disabled?
  @disabled || CanTango.config.permits.disabled?(permit_type, name)
end

#modesObject



34
35
36
# File 'lib/cantango/permit/base.rb', line 34

def modes
  self.class.modes
end

#nameObject



19
20
21
# File 'lib/cantango/permit/base.rb', line 19

def name
  self.class.permit_name self.class
end

#permit_typeObject



38
39
40
# File 'lib/cantango/permit/base.rb', line 38

def permit_type
  self.class.permit_type
end

#sync_rules!Object



70
71
72
73
# File 'lib/cantango/permit/base.rb', line 70

def sync_rules!
  ability.rules << (rules - ability_rules)
  ability.rules.flatten!
end

#valid?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


50
51
52
# File 'lib/cantango/permit/base.rb', line 50

def valid?
  raise NotImplementedError
end