Class: RailsIam::Authorization::AuthorizationRule

Inherits:
Data
  • Object
show all
Defined in:
app/services/rails_iam/authorization/authorization_rule.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#exceptObject (readonly)

Returns the value of attribute except

Returns:

  • (Object)

    the current value of except



5
6
7
# File 'app/services/rails_iam/authorization/authorization_rule.rb', line 5

def except
  @except
end

#onlyObject (readonly)

Returns the value of attribute only

Returns:

  • (Object)

    the current value of only



5
6
7
# File 'app/services/rails_iam/authorization/authorization_rule.rb', line 5

def only
  @only
end

#permission_matchObject (readonly)

Returns the value of attribute permission_match

Returns:

  • (Object)

    the current value of permission_match



5
6
7
# File 'app/services/rails_iam/authorization/authorization_rule.rb', line 5

def permission_match
  @permission_match
end

#permissionsObject (readonly)

Returns the value of attribute permissions

Returns:

  • (Object)

    the current value of permissions



5
6
7
# File 'app/services/rails_iam/authorization/authorization_rule.rb', line 5

def permissions
  @permissions
end

#role_matchObject (readonly)

Returns the value of attribute role_match

Returns:

  • (Object)

    the current value of role_match



5
6
7
# File 'app/services/rails_iam/authorization/authorization_rule.rb', line 5

def role_match
  @role_match
end

#rolesObject (readonly)

Returns the value of attribute roles

Returns:

  • (Object)

    the current value of roles



5
6
7
# File 'app/services/rails_iam/authorization/authorization_rule.rb', line 5

def roles
  @roles
end

Instance Method Details

#authorizer_arguments(inferred_permission: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'app/services/rails_iam/authorization/authorization_rule.rb', line 23

def authorizer_arguments(inferred_permission: nil)
  {
    required_roles: roles,
    required_permissions: permissions,
    inferred_permission: inferred_permission,
    role_match: role_match,
    permission_match: permission_match,
  }
end

#matches?(action) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
# File 'app/services/rails_iam/authorization/authorization_rule.rb', line 13

def matches?(action)
  action = action.to_sym

  return Array(only).map(&:to_sym).include?(action) if only.present?

  return Array(except).map(&:to_sym).exclude?(action) if except.present?

  true
end

#valid?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'app/services/rails_iam/authorization/authorization_rule.rb', line 33

def valid?
  roles.any? || permissions.any?
end