Class Authorization::Reader::DSLReader
In: lib/declarative_authorization/reader.rb
Parent: Object

Top-level reader, parses the methods privileges and authorization. authorization takes a block with authorization rules as described in AuthorizationRulesReader. The block to privileges defines privilege hierarchies, as described in PrivilegesReader.

Methods

factory   load   load   load!   new   parse  

Public Class methods

ensures you get back a DSLReader if you provide a:

  DSLReader - you will get it back.
  String or Array - it will treat it as if you have passed a path or an array of paths and attempt to load those.

[Source]

    # File lib/declarative_authorization/reader.rb, line 71
71:       def self.factory(obj)
72:         case obj
73:         when Reader::DSLReader
74:           obj
75:         when String, Array
76:           load(obj)
77:         end
78:       end

Loads and parses DSL files and returns a new reader

[Source]

     # File lib/declarative_authorization/reader.rb, line 105
105:       def self.load (dsl_files)
106:         # TODO cache reader in production mode?
107:         reader = new
108:         dsl_files = [dsl_files].flatten
109:         dsl_files.each do |file|
110:           reader.load(file)
111:         end
112:         reader
113:       end

[Source]

    # File lib/declarative_authorization/reader.rb, line 57
57:       def initialize ()
58:         @privileges_reader = PrivilegesReader.new
59:         @auth_rules_reader = AuthorizationRulesReader.new
60:       end

Public Instance methods

Load and parse a DSL from the given file name.

[Source]

    # File lib/declarative_authorization/reader.rb, line 93
93:       def load (dsl_file)
94:         parse(File.read(dsl_file), dsl_file) if File.exist?(dsl_file)
95:       end

Load and parse a DSL from the given file name. Raises Authorization::Reader::DSLFileNotFoundError if the file cannot be found.

[Source]

     # File lib/declarative_authorization/reader.rb, line 99
 99:       def load! (dsl_file)
100:         raise ::Authorization::Reader::DSLFileNotFoundError, "Error reading authorization rules file with path '#{dsl_file}'!  Please ensure it exists and that it is accessible." unless File.exist?(dsl_file)
101:         load(dsl_file)
102:       end

Parses a authorization DSL specification from the string given in dsl_data. Raises DSLSyntaxError if errors occur on parsing.

[Source]

    # File lib/declarative_authorization/reader.rb, line 82
82:       def parse (dsl_data, file_name = nil)
83:         if file_name
84:           DSLMethods.new(self).instance_eval(dsl_data, file_name)
85:         else
86:           DSLMethods.new(self).instance_eval(dsl_data)
87:         end
88:       rescue SyntaxError, NoMethodError, NameError => e
89:         raise DSLSyntaxError, "Illegal DSL syntax: #{e}"
90:       end

[Validate]