lib/cancan-permits/loader/permissions_loader.rb in cancan-permits-0.3.5 vs lib/cancan-permits/loader/permissions_loader.rb in cancan-permits-0.3.6

- old
+ new

@@ -4,11 +4,11 @@ def initialize file_name begin if file_name.nil? || !File.file?(file_name) # raise ArgumentError, "PermissionsLoader Error: The permissions file #{file_name} could not be found" - puts "PermissionsLoader Error: The permissions file #{file_name} could not be found" + # puts "PermissionsLoader Error: The permissions file #{file_name} could not be found" return nil end yml_content = YAML.load_file(file_name) parser = PermissionsParser.new @@ -31,16 +31,36 @@ def self.load_licenses name = nil name ||= licenses_config_file PermissionsLoader.new name end + + def self.load_permits name = nil + name ||= permits_config_file + PermissionsLoader.new name + end + def self.permits_config_file + # raise '#user_permissions_config_file only works in a Rails app enviroment' if !defined? Rails + get_config_file 'permits' + end + def self.user_permissions_config_file # raise '#user_permissions_config_file only works in a Rails app enviroment' if !defined? Rails - File.join(::Rails.root, 'config', 'user_permissions.yml') if defined? Rails + get_config_file 'user_permissions' end def self.licenses_config_file # raise '#licenses_config_file only works in a Rails app enviroment' if !defined? Rails - File.join(::Rails.root, 'config', 'licenses.yml') if defined? Rails + get_config_file 'licenses' + end + + protected + + def self.get_config_file name + File.join(::Rails.root, 'config', "#{name}.yml") if rails? + end + + def self.rails? + defined?(Rails) && Rails.respond_to?(:root) end end \ No newline at end of file