| 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.
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.
# 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
# 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
# File lib/declarative_authorization/reader.rb, line 57
57: def initialize ()
58: @privileges_reader = PrivilegesReader.new
59: @auth_rules_reader = AuthorizationRulesReader.new
60: end
Load and parse a DSL from the given file name. Raises Authorization::Reader::DSLFileNotFoundError if the file cannot be found.
# 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.
# 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