Module: CanTango

Defined in:
lib/cantango/permits/permit.rb,
lib/cantango.rb,
lib/cantango/api.rb,
lib/cantango/cache.rb,
lib/cantango/model.rb,
lib/cantango/rails.rb,
lib/cantango/rules.rb,
lib/cantango/users.rb,
lib/cantango/engine.rb,
lib/cantango/ability.rb,
lib/cantango/filters.rb,
lib/cantango/helpers.rb,
lib/cantango/permits.rb,
lib/cantango/api/user.rb,
lib/cantango/rules/dsl.rb,
lib/cantango/api/common.rb,
lib/cantango/users/user.rb,
lib/cantango/api/options.rb,
lib/cantango/rules/scope.rb,
lib/cantango/api/user/can.rb,
lib/cantango/rails/engine.rb,
lib/cantango/ability/cache.rb,
lib/cantango/ability/scope.rb,
lib/cantango/configuration.rb,
lib/cantango/helpers/debug.rb,
lib/cantango/permit_engine.rb,
lib/cantango/rails/railtie.rb,
lib/cantango/rules/adaptor.rb,
lib/cantango/adapter/moneta.rb,
lib/cantango/adapter/moneta.rb,
lib/cantango/adapter/moneta.rb,
lib/cantango/api/attributes.rb,
lib/cantango/api/user/scope.rb,
lib/cantango/cached_ability.rb,
lib/cantango/filters/filter.rb,
lib/cantango/user_ac_engine.rb,
lib/cantango/permits/license.rb,
lib/cantango/ability/executor.rb,
lib/cantango/ability_executor.rb,
lib/cantango/adapter/compiler.rb,
lib/cantango/api/user/ability.rb,
lib/cantango/api/user/session.rb,
lib/cantango/api/user_account.rb,
lib/cantango/cache/hash_cache.rb,
lib/cantango/permits/executor.rb,
lib/cantango/rules/rule_class.rb,
lib/cantango/users/masquerade.rb,
lib/cantango/ability/cache/key.rb,
lib/cantango/permission_engine.rb,
lib/cantango/cache/moneta_cache.rb,
lib/cantango/configuration/user.rb,
lib/cantango/permit_engine/util.rb,
lib/cantango/users/user_account.rb,
lib/cantango/configuration/debug.rb,
lib/cantango/configuration/guest.rb,
lib/cantango/configuration/modes.rb,
lib/cantango/configuration/roles.rb,
lib/cantango/configuration/users.rb,
lib/cantango/filters/role_filter.rb,
lib/cantango/permits/role_permit.rb,
lib/cantango/permits/user_permit.rb,
lib/cantango/rules/adaptor/mongo.rb,
lib/cantango/rules/user_relation.rb,
lib/cantango/ability/cache/reader.rb,
lib/cantango/ability/cache/writer.rb,
lib/cantango/ability/role_helpers.rb,
lib/cantango/ability/user_helpers.rb,
lib/cantango/api/user_account/can.rb,
lib/cantango/configuration/models.rb,
lib/cantango/helpers/role_methods.rb,
lib/cantango/permit_engine/finder.rb,
lib/cantango/ability/cache_helpers.rb,
lib/cantango/configuration/ability.rb,
lib/cantango/configuration/engines.rb,
lib/cantango/configuration/factory.rb,
lib/cantango/configuration/permits.rb,
lib/cantango/permit_engine/builder.rb,
lib/cantango/permit_engine/factory.rb,
lib/cantango/rules/adaptor/generic.rb,
lib/cantango/ability/cache/kompiler.rb,
lib/cantango/ability/engine_helpers.rb,
lib/cantango/ability/permit_helpers.rb,
lib/cantango/api/user_account/scope.rb,
lib/cantango/configuration/adapters.rb,
lib/cantango/configuration/autoload.rb,
lib/cantango/configuration/registry.rb,
lib/cantango/permit_engine/executor.rb,
lib/cantango/permits/account_permit.rb,
lib/cantango/permits/permit/execute.rb,
lib/cantango/permits/permit/license.rb,
lib/cantango/permission_engine/store.rb,
lib/cantango/ability/cache/base_cache.rb,
lib/cantango/api/user_account/ability.rb,
lib/cantango/api/user_account/session.rb,
lib/cantango/configuration/categories.rb,
lib/cantango/permission_engine/loader.rb,
lib/cantango/permission_engine/parser.rb,
lib/cantango/rules/adaptor/relational.rb,
lib/cantango/ability/cache/rules_cache.rb,
lib/cantango/configuration/role_groups.rb,
lib/cantango/filters/role_group_filter.rb,
lib/cantango/permission_engine/factory.rb,
lib/cantango/permits/role_group_permit.rb,
lib/cantango/rails/helpers/base_helper.rb,
lib/cantango/rails/helpers/view_helper.rb,
lib/cantango/rules/adaptor/data_mapper.rb,
lib/cantango/ability/cache/moneta_cache.rb,
lib/cantango/ability/masquerade_helpers.rb,
lib/cantango/ability/permission_helpers.rb,
lib/cantango/configuration/models/mongo.rb,
lib/cantango/configuration/user_account.rb,
lib/cantango/permission_engine/compiler.rb,
lib/cantango/permission_engine/selector.rb,
lib/cantango/permit_engine/builder/base.rb,
lib/cantango/permit_engine/role_matcher.rb,
lib/cantango/permits/role_permit/finder.rb,
lib/cantango/permits/user_permit/finder.rb,
lib/cantango/ability/cache/session_cache.rb,
lib/cantango/configuration/engines/cache.rb,
lib/cantango/configuration/engines/store.rb,
lib/cantango/configuration/hash_registry.rb,
lib/cantango/configuration/role_registry.rb,
lib/cantango/configuration/user_accounts.rb,
lib/cantango/permission_engine/collector.rb,
lib/cantango/permission_engine/evaluator.rb,
lib/cantango/permission_engine/statement.rb,
lib/cantango/permit_engine/compatibility.rb,
lib/cantango/permit_engine/executor/base.rb,
lib/cantango/permits/role_permit/builder.rb,
lib/cantango/permits/user_permit/builder.rb,
lib/cantango/rules/adaptor/active_record.rb,
lib/cantango/configuration/engines/engine.rb,
lib/cantango/configuration/engines/permit.rb,
lib/cantango/configuration/models/actions.rb,
lib/cantango/configuration/models/generic.rb,
lib/cantango/configuration/models/mongoid.rb,
lib/cantango/permission_engine/permission.rb,
lib/cantango/permission_engine/statements.rb,
lib/cantango/permission_engine/yaml_store.rb,
lib/cantango/permits/permit/class_methods.rb,
lib/cantango/configuration/engines/user_ac.rb,
lib/cantango/configuration/permit_registry.rb,
lib/cantango/permission_engine/loader/base.rb,
lib/cantango/permission_engine/parser/rule.rb,
lib/cantango/permit_engine/executor/system.rb,
lib/cantango/permits/account_permit/finder.rb,
lib/cantango/permission_engine/moneta_store.rb,
lib/cantango/permission_engine/parser/regex.rb,
lib/cantango/permits/account_permit/builder.rb,
lib/cantango/permission_engine/selector/base.rb,
lib/cantango/permit_engine/executor/abstract.rb,
lib/cantango/rails/helpers/controller_helper.rb,
lib/cantango/configuration/candidate_registry.rb,
lib/cantango/configuration/engines/permission.rb,
lib/cantango/configuration/models/data_mapper.rb,
lib/cantango/permission_engine/parser/default.rb,
lib/cantango/permission_engine/selector/roles.rb,
lib/cantango/permission_engine/selector/users.rb,
lib/cantango/permits/role_group_permit/finder.rb,
lib/cantango/permission_engine/parser/category.rb,
lib/cantango/permits/role_group_permit/builder.rb,
lib/cantango/configuration/models/active_record.rb,
lib/cantango/permission_engine/parser/ownership.rb,
lib/cantango/permission_engine/loader/categories.rb,
lib/cantango/permission_engine/parser/categories.rb,
lib/cantango/permission_engine/selector/licenses.rb,
lib/cantango/permission_engine/loader/permissions.rb,
lib/cantango/permission_engine/parser/permissions.rb,
lib/cantango/users/masquerade/session_active_user.rb,
lib/cantango/permission_engine/parser/relationship.rb,
lib/cantango/permission_engine/selector/user_types.rb,
lib/cantango/permit_engine/builder/special_permits.rb,
lib/cantango/permission_engine/selector/role_groups.rb,
lib/cantango/permission_engine/selector/account_types.rb

Overview

ensures compatibility with CanCan 1.5+ and 1.4-

Defined Under Namespace

Modules: Api, Cache, Filters, Helpers, Model, Permits, Rails, RailsAutoLoader, Rules, Users Classes: Ability, AbilityExecutor, CachedAbility, Configuration, Engine, PermissionEngine, PermitEngine, RailsEngine, Railtie, UserAcEngine

Constant Summary collapse

License =
CanTango::Permits::License

Class Method Summary collapse

Class Method Details

.clear_permits_executed!Object



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

def clear_permits_executed!
  config.permits.clear_executed!
end

.configure {|conf| ... } ⇒ Object Also known as: config

Yields:

  • (conf)


21
22
23
24
25
# File 'lib/cantango.rb', line 21

def configure &block
  conf = CanTango::Configuration.instance
  yield conf if block
  conf
end

.debug!Object



53
54
55
# File 'lib/cantango.rb', line 53

def debug!
  config.debug.set :on
end

.debug?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/cantango.rb', line 61

def debug?
  config.debug.on?
end

.debug_ability(candidate, actions, subjects, *extra_args) ⇒ Object



43
44
45
46
47
# File 'lib/cantango.rb', line 43

def debug_ability candidate, actions, subjects, *extra_args
  puts "Ability: #{actions} on #{subjects}"
  puts "permits allowed:" << permits_allowed(candidate, actions, subjects, *extra_args).inspect
  puts "permits denied:"  << permits_denied(candidate, actions, subjects, *extra_args).inspect
end

.debug_off!Object



57
58
59
# File 'lib/cantango.rb', line 57

def debug_off!
  config.debug.set :off
end

.debug_permits_registryObject



39
40
41
# File 'lib/cantango.rb', line 39

def debug_permits_registry
  puts "permits registry:" << CanTango.config.permits.show_all.inspect
end

.include_helpers(scope) ⇒ Object

Include helpers in the given scope to AC and AV. “Borrowed” from devise



4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/cantango/rails/engine.rb', line 4

def self.include_helpers(scope)
  # Seems like the order of initializers is important! ActiveRecord should go first!
  ActiveSupport.on_load(:active_record) do
    RailsAutoLoader.load_models! if CanTango.config.autoload.models?
  end

  ActiveSupport.on_load(:action_controller) do
    include scope::Rails::Helpers::ControllerHelper
  end

  ActiveSupport.on_load(:action_view) do
    include scope::Rails::Helpers::ViewHelper
  end
end

.permits_allowed(candidate, actions, subjects, *extra_args) ⇒ Object



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

def permits_allowed candidate, actions, subjects, *extra_args
  raise "Debugging has not been turned on. Turn it on using: CanTango.debug!" if CanTango.config.debug.off?
  config.permits.allowed candidate, actions, subjects, *extra_args
end

.permits_denied(candidate, actions, subjects, *extra_args) ⇒ Object



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

def permits_denied candidate, actions, subjects, *extra_args
  raise "Debugging has not been turned on. Turn it on using: CanTango.debug!" if CanTango.config.debug.off?
  config.permits.denied candidate, actions, subjects, *extra_args
end