Class: CanTango::Permits::Permit

Inherits:
Object
  • Object
show all
Extended by:
ClassMethods
Includes:
Api::Attributes, Helpers::Debug, CanTango::PermitEngine::Compatibility, CanTango::PermitEngine::RoleMatcher, CanTango::PermitEngine::Util, License, Execute, Rules
Defined in:
lib/cantango/permits/permit.rb,
lib/cantango/permits/permit/execute.rb,
lib/cantango/permits/permit/license.rb,
lib/cantango/permits/permit/class_methods.rb

Defined Under Namespace

Modules: ClassMethods, Execute, License

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClassMethods

account_name, first_name, type

Methods included from CanTango::PermitEngine::RoleMatcher

#role_group_match?, #role_match?

Methods included from CanTango::PermitEngine::Compatibility

#rules, #rules_1_4, #rules_1_5

Methods included from CanTango::PermitEngine::Util

#localhost_manager?, #permit_name, #role

Methods included from Execute

#cached_rules, #dynamic_rules, #execute, #executor, #include_cached, #include_non_cached, #non_cached_rules, #permit?, #permit_rules, #run_rule_methods, #static_rules

Methods included from Rules::Dsl

included, #scope

Methods included from Helpers::Debug

#debug

Constructor Details

#initialize(ability) ⇒ Permit

creates the permit



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

def initialize ability
  @ability  = ability
end

Instance Attribute Details

#abilityObject (readonly)

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



17
18
19
# File 'lib/cantango/permits/permit.rb', line 17

def ability
  @ability
end

#disabledObject (readonly)

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



17
18
19
# File 'lib/cantango/permits/permit.rb', line 17

def disabled
  @disabled
end

Class Method Details

.available_permitsObject



29
30
31
# File 'lib/cantango/permits/permit.rb', line 29

def self.available_permits
  CanTango.config.permits.available_permits
end

.hash_keyObject



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

def self.hash_key
  nil
end

.inherited(subclass) ⇒ Object



21
22
23
# File 'lib/cantango/permits/permit.rb', line 21

def self.inherited(subclass)
  register subclass.name.split('::').last.sub(/Permit$/, '').underscore.to_sym, subclass
end

.register(permit, subclass) ⇒ Object



25
26
27
# File 'lib/cantango/permits/permit.rb', line 25

def self.register permit, subclass
  available_permits[permit] = subclass
end

Instance Method Details

#ability_rulesObject



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

def ability_rules
  ability.send :rules
end

#ability_sync!Object



86
87
88
89
# File 'lib/cantango/permits/permit.rb', line 86

def ability_sync!
  ability_rules << (rules - ability_rules)
  ability_rules.flatten!
end

#any(reg_exp) ⇒ Object



66
67
68
# File 'lib/cantango/permits/permit.rb', line 66

def any reg_exp
  config.models.by_reg_exp reg_exp
end

#category(label) ⇒ Object



62
63
64
# File 'lib/cantango/permits/permit.rb', line 62

def category label
  config.models.by_category label
end

#disable!Object



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

def disable!
  @disabled = true
end

#disabled?Boolean

Returns:

  • (Boolean)


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

def disabled?
  @disabled || config_disabled?
end

#localhost?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/cantango/permits/permit.rb', line 78

def localhost?
  config.localhost_list.include? request.host
end

#permit_typeObject



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

def permit_type
  self.class.type
end

#publichost?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/cantango/permits/permit.rb', line 82

def publichost?
  !localhost?
end

#valid_for?(subject) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


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

def valid_for? subject
  raise NotImplementedError
end