module AuthorizationNext::Base::EvalParser
Public Instance Methods
process_role( role_name )
click to toggle source
# File lib/authorization_next/publishare/parser.rb, line 81 def process_role( role_name ) return false if @current_user.nil? raise( UserDoesntImplementRoles, "User doesn't implement #has_role?" ) if not @current_user.respond_to? :has_role? @current_user.has_role?( role_name ) end
process_role_of_model( role_name, model_name )
click to toggle source
# File lib/authorization_next/publishare/parser.rb, line 75 def process_role_of_model( role_name, model_name ) model = get_model( model_name ) raise( ModelDoesntImplementRoles, "Model (#{model_name}) doesn't implement #accepts_role?" ) if not model.respond_to? :accepts_role? model.send( :accepts_role?, role_name, @current_user ) end
replace_role( str )
click to toggle source
# File lib/authorization_next/publishare/parser.rb, line 57 def replace_role( str ) role_regex = '\s*(\'\s*(.+)\s*\'|([A-Za-z]\w*))\s*' parse_regex = Regexp.new(role_regex) str.gsub(parse_regex) do |match| if BOOLEAN_OPS.include?($3) " #{match} " else " process_role('#{$2 || $3}') " end end end
replace_role_of_model( str )
click to toggle source
# File lib/authorization_next/publishare/parser.rb, line 69 def replace_role_of_model( str ) str.gsub(/<(\d+)>/) do |match| @replacements[$1.to_i] end end
replace_temporarily_role_of_model( str )
click to toggle source
# File lib/authorization_next/publishare/parser.rb, line 47 def replace_temporarily_role_of_model( str ) role_regex = '\s*(\'\s*(.+)\s*\'|(\w+))\s+' model_regex = '\s+(:*\w+)' parse_regex = Regexp.new(role_regex + '(' + VALID_PREPOSITIONS.join('|') + ')' + model_regex) str.gsub(parse_regex) do |match| @replacements.push " process_role_of_model('#{$2 || $3}', '#{$5}') " " <#{@replacements.length-1}> " end end