Class: Ixtlan::Guard::Config
- Inherits:
-
Object
- Object
- Ixtlan::Guard::Config
- Defined in:
- lib/ixtlan/guard/guard_config.rb
Instance Method Summary collapse
- #allowed_groups(resource, action) ⇒ Object
- #has_guard?(resource) ⇒ Boolean
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #map_of_all ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
6 7 8 9 10 |
# File 'lib/ixtlan/guard/guard_config.rb', line 6 def initialize( = {}) @guards_dir = [:guards_dir] @load_method = [: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
21 22 23 |
# File 'lib/ixtlan/guard/guard_config.rb', line 21 def has_guard?(resource) File.exists? yaml_file(resource) end |
#map_of_all ⇒ Object
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 |