class Authoreyes::Parser::DSLParser

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/authoreyes/parser/dsl_parser.rb, line 26
def self.factory(obj)
  case obj
  when Parser::DSLParser
    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/authoreyes/parser/dsl_parser.rb, line 61
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/authoreyes/parser/dsl_parser.rb, line 11
def initialize
  @privileges_reader = PrivilegesReader.new
  @auth_rules_reader = AuthorizationRulesParser.new
end

Public Instance Methods

load(dsl_file) click to toggle source

Load and parse a DSL from the given file name.

# File lib/authoreyes/parser/dsl_parser.rb, line 48
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/authoreyes/parser/dsl_parser.rb, line 55
def load!(dsl_file)
  raise ::Authoreyes::Parser::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 an authorization DSL specification from the string given in dsl_data. Raises DSLSyntaxError if errors occur on parsing.

# File lib/authoreyes/parser/dsl_parser.rb, line 37
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