Class: PostPolicy::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/postpolicy/config.rb

Defined Under Namespace

Classes: Db

Class Method Summary collapse

Class Method Details

.load(config_hash) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/postpolicy/config.rb', line 16

def self.load( config_hash ) 
  acls = Hash.new { |hsh, key| hsh[key] = Array.new }
  config_acls = config_hash.delete( "acl" )
  config_acls.each_pair do |human_name, klass_value_maps|
    klass_value_maps.each_pair do |klass, value|
      acls[human_name] << ACL.const_get(klass.classify).new( resolve_datasource( value ) )
    end
  end
  actions = config_hash.delete( "action" )
  accesses = config_hash.delete( "access" )
  accesses.each_pair do |action, acl|
    AccessManager << Access.new( acls[acl], actions[action] )
  end
  Db.load( config_hash["database"] )
end

.load_from_file(filename) ⇒ Object



12
13
14
# File 'lib/postpolicy/config.rb', line 12

def self.load_from_file( filename )
  load( YAML.load_file( filename ) )
end