Class: Authorization::Reader::DSLReader

Inherits:
Object
  • Object
show all
Defined in:
lib/declarative_authorization/reader.rb

Overview

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.

Defined Under Namespace

Classes: DSLMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDSLReader

Returns a new instance of DSLReader.



51
52
53
54
# File 'lib/declarative_authorization/reader.rb', line 51

def initialize ()
  @privileges_reader = PrivilegesReader.new
  @auth_rules_reader = AuthorizationRulesReader.new
end

Instance Attribute Details

#auth_rules_readerObject (readonly)

:nodoc:



49
50
51
# File 'lib/declarative_authorization/reader.rb', line 49

def auth_rules_reader
  @auth_rules_reader
end

#privileges_readerObject (readonly)

:nodoc:



49
50
51
# File 'lib/declarative_authorization/reader.rb', line 49

def privileges_reader
  @privileges_reader
end

Class Method Details

.load(dsl_file) ⇒ Object

Loads and parses a DSL from the given file name.



69
70
71
72
73
74
# File 'lib/declarative_authorization/reader.rb', line 69

def self.load (dsl_file)
  # TODO cache reader in production mode?
  reader = new
  reader.parse(File.read(dsl_file), dsl_file)
  reader
end

Instance Method Details

#parse(dsl_data, file_name = nil) ⇒ Object

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



58
59
60
61
62
63
64
65
66
# File 'lib/declarative_authorization/reader.rb', line 58

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