module FlexibleAccessibility::ControllerMethods::ClassMethods

Public Instance Methods

authorize(args={}) click to toggle source

Macro for define routes table with authorization

# File lib/flexible_accessibility/controller_methods.rb, line 11
  def authorize(args={})
arguments = parse_arguments(args)

validate_arguments(arguments)

self.instance_variable_set(:@_routes_table, arguments)        
  end
skip_authorization_here() click to toggle source

Compatibility with previous versions

# File lib/flexible_accessibility/controller_methods.rb, line 6
def skip_authorization_here
  authorize :skip => :all
end

Private Instance Methods

parse_arguments(args={}) click to toggle source

Parse arguments from macro call

# File lib/flexible_accessibility/controller_methods.rb, line 22
def parse_arguments(args={})
  result = {}
  (result[:all] = ['all'].to_set) and return result if args.to_s == 'all'
  [:only, :except, :skip].each do |key|
    unless args[key].nil?
      result[key] = [args[key].to_s].to_set and next if args[key].to_s == 'all' && key == :skip
      raise ActionsValueException unless args[key].instance_of?(Array)
      result[key] = args[key].map!{ |v| v.to_s }.to_set
    end
  end
  result
end
validate_arguments(args={}) click to toggle source

Validate arguments from macro call

# File lib/flexible_accessibility/controller_methods.rb, line 36
def validate_arguments(args={})
  return if args.count == 1 && args.keys.include?(:all)
  only_options = args[:only] || Set.new
  except_options =  args[:except] || Set.new
  skip_options = args[:skip] || Set.new
  unless (only_options & except_options).empty? &&
         (only_options & skip_options).empty?
    raise IncorrectArgumentException.new(nil, 'The same arguments shouldn\'t be used with different keys excluding except and skip')
  end
  if args[:skip] == 'all' && args.count > 1
    raise IncorrectArgumentException.new(nil, 'Option \'skip\' with argument \'all\' shouldn\'t be used with another options')
  end
end