Class: Ixtlan::Guard::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ixtlan/guard/guard_config.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.

Raises:



6
7
8
9
10
# File 'lib/ixtlan/guard/guard_config.rb', line 6

def initialize(options = {})
  @guards_dir = options[:guards_dir]
  @load_method = options[:cache] ? :cached_load_from_yaml_file : :load_from_yaml_file
  raise GuardException.new("guards directory does not exists: #{@guards_dir}") unless File.directory?(@guards_dir)
end

Instance Method Details

#allowed_groups(resource, action) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/ixtlan/guard/guard_config.rb', line 12

def allowed_groups(resource, action)
  if resource && action
    groups = send(@load_method, resource.to_s)
    groups[action.to_s] || groups["defaults"] || []
  else
    []
  end
end

#has_guard?(resource) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/ixtlan/guard/guard_config.rb', line 21

def has_guard?(resource)
  File.exists? yaml_file(resource)
end

#map_of_allObject



25
26
27
28
29
30
31
# File 'lib/ixtlan/guard/guard_config.rb', line 25

def map_of_all
  result = {}
  Dir[File.join(@guards_dir, "*_guard.yml")].each do |file|
    result.merge!(YAML.load_file(file))
  end
  result
end