Sha256: 8d2fe0be11aa1cbb00fffb9d94660493d7a2fa4e9bdd113bd216754029020351

Contents?: true

Size: 1.19 KB

Versions: 22

Compression:

Stored size: 1.19 KB

Contents

RoleAuthorization::Rules.define :all do
  true
end

RoleAuthorization::Rules.define :role do
  if controller_instance.current_user.blank?
    false
  else
    scope = if options[:scope]
              if options[:scope].is_a?(Proc)
                controller_instance.instance_eval(&options[:scope])
              else
                options[:scope]
              end
            else
              :global
            end

    controller_instance.current_user.roles(scope).include?(role)
  end
end

RoleAuthorization::Rules.define :user do
  if controller_instance.current_user.blank?
    false
  else
    if options[:resource]
      check_method = options[:check] || :id
      resource_instances = controller_instance.instance_eval(&options[:resource])
      resource_instances = [resource_instances] unless resource_instances.is_a?(Array)

      resource_instances.map do |resource_instance|
        controller_instance.current_user.id == resource_instance.try(check_method)
      end.include?(true)
    else
      false
    end
  end
end

RoleAuthorization::Rules.define :custom do
  unless options[:block].nil?
    true if controller_instance.instance_eval(&options[:block]) == true
  else
    false
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
role_authorization-0.9.6 lib/role_authorization/rules/defaults.rb
role_authorization-0.9.5 lib/role_authorization/rules/defaults.rb
role_authorization-0.9.4 lib/role_authorization/rules/defaults.rb
role_authorization-0.9.3 lib/role_authorization/rules/defaults.rb
role_authorization-0.9.2 lib/role_authorization/rules/defaults.rb
role_authorization-0.9.1 lib/role_authorization/rules/defaults.rb
role_authorization-0.9.0 lib/role_authorization/rules/defaults.rb
role_authorization-0.6.2 lib/role_authorization/rules/defaults.rb
role_authorization-0.6.1 lib/role_authorization/rules/defaults.rb
role_authorization-0.6.0 lib/role_authorization/rules/defaults.rb
role_authorization-0.5.9 lib/role_authorization/rules/defaults.rb
role_authorization-0.5.8 lib/role_authorization/rules/defaults.rb
role_authorization-0.5.7 lib/role_authorization/rules/defaults.rb
role_authorization-0.5.6 lib/role_authorization/rules/defaults.rb
role_authorization-0.5.5 lib/role_authorization/rules/defaults.rb
role_authorization-0.5.4 lib/role_authorization/rules/defaults.rb
role_authorization-0.5.3 lib/role_authorization/rules/defaults.rb
role_authorization-0.5.2 lib/role_authorization/rules/defaults.rb
role_authorization-0.5.1 lib/role_authorization/rules/defaults.rb
role_authorization-0.5.0 lib/role_authorization/rules/defaults.rb