Sha256: 577dce95eb46c97908e12d11b4cda3f598e4717ecce3fb373e2901d77c04173a

Contents?: true

Size: 1.21 KB

Versions: 8

Compression:

Stored size: 1.21 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(options[:scope] || :global).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

8 entries across 8 versions & 1 rubygems

Version Path
role_authorization-0.4.3 lib/role_authorization/rules/defaults.rb
role_authorization-0.4.2 lib/role_authorization/rules/defaults.rb
role_authorization-0.4.1 lib/role_authorization/rules/defaults.rb
role_authorization-0.4.0 lib/role_authorization/rules/defaults.rb
role_authorization-0.3.9 lib/role_authorization/rules/defaults.rb
role_authorization-0.3.8 lib/role_authorization/rules/defaults.rb
role_authorization-0.3.7 lib/role_authorization/rules/defaults.rb
role_authorization-0.3.6 lib/role_authorization/rules/defaults.rb