class Authorization::Reader::DSLReader
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
.
Public Class Methods
factory(obj)
click to toggle source
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 def self.factory(obj) case obj when Reader::DSLReader obj when String, Array load(obj) end end
load(dsl_files)
click to toggle source
Loads and parses DSL files and returns a new reader
# File lib/declarative_authorization/reader.rb, line 105 def self.load (dsl_files) # TODO cache reader in production mode? reader = new dsl_files = [dsl_files].flatten dsl_files.each do |file| reader.load(file) end reader end
new()
click to toggle source
# File lib/declarative_authorization/reader.rb, line 57 def initialize () @privileges_reader = PrivilegesReader.new @auth_rules_reader = AuthorizationRulesReader.new end
Public Instance Methods
load(dsl_file)
click to toggle source
Load and parse a DSL from the given file name.
# File lib/declarative_authorization/reader.rb, line 93 def load (dsl_file) parse(File.read(dsl_file), dsl_file) if File.exist?(dsl_file) end
load!(dsl_file)
click to toggle source
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 def load! (dsl_file) 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) load(dsl_file) end
parse(dsl_data, file_name = nil)
click to toggle source
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 def parse (dsl_data, file_name = nil) if file_name DSLMethods.new(self).instance_eval(dsl_data, file_name) else DSLMethods.new(self).instance_eval(dsl_data) end rescue SyntaxError, NoMethodError, NameError => e raise DSLSyntaxError, "Illegal DSL syntax: #{e}" end