Module: AnnotationSecurity

Defined in:
lib/annotation_security.rb,
lib/annotation_security.rb,
lib/annotation_security/exec.rb,
lib/annotation_security/exceptions.rb,
lib/annotation_security/exceptions.rb

Overview

lib/annotation_security/exceptions.rb

Provides some Exceptions used within AnnotationSecurity

Defined Under Namespace

Modules: ActionController, Exec, Helper, Rails, Resource, Role, User Classes: AbstractPolicy, AbstractStaticPolicy, PolicyFactory, PolicyManager, RelationLoader, ResourceManager, RightLoader, Rule, RuleError, RuleExecutionError, RuleNotFoundError, RuleSet, SecurityError, UserWrapper, Utils

Constant Summary collapse

VERSION =
'1.3.1'

Class Method Summary collapse

Class Method Details

.define_relations(*resources, &block) ⇒ Object

Defines relations specified in block.

See AnnotationSecurity::RelationLoader for details



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

def self.define_relations(*resources,&block)
  RelationLoader.define_relations(*resources,&block)
end

.define_rights(hash) ⇒ Object

Defines rights specified in hash.

See AnnotationSecurity::RightLoader for details



69
70
71
# File 'lib/annotation_security.rb', line 69

def self.define_rights(hash)
  RightLoader.define_rights(hash)
end

.init_rails(config) ⇒ Object

Initializes AnnotationSecurity for a Rails application and loads Rails specific parts of the library.

This method is called by ‘init.rb`, which is run by Rails on startup.

  • binding [Binding] The context of the ‘init.rb` file.



88
89
90
91
92
93
# File 'lib/annotation_security.rb', line 88

def self.init_rails(config)
  dir = File.dirname(__FILE__)

  require dir + '/annotation_security/rails/extensions'
  AnnotationSecurity::Rails.init!(config)
end

.load_relations(fname) ⇒ Object

Load the file specified by fname. The file will be reloaded automatically if reset is called.

See AnnotationSecurity::RelationLoader for details.



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

def self.load_relations(fname)
  PolicyManager.add_file(fname, 'rb')
end

.load_rights(fname, ext = 'yml') ⇒ Object

Load the file specified by fname. The file will be reloaded automatically if reset is called.

See AnnotationSecurity::RightLoader for details.



41
42
43
44
45
46
# File 'lib/annotation_security.rb', line 41

def self.load_rights(fname, ext = 'yml')
  # The file is expected to be a yaml file.
  # However, it is also possible to use a ruby file that uses
  # AnnotationSecurity.define_rights. In this case, ext should be 'rb'.
  PolicyManager.add_file(fname, ext)
end

.resetObject

Reloads all files that were loaded with load_rights or load_relations.

In development mode, reset is being executed before each request.



77
78
79
# File 'lib/annotation_security.rb', line 77

def self.reset
  PolicyManager.reset
end