Class: Seira::Teleport::RoleRequirement

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/seira/teleport/role_requirements.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(requirement) ⇒ RoleRequirement

Returns a new instance of RoleRequirement.



8
9
10
11
12
13
# File 'lib/seira/teleport/role_requirements.rb', line 8

def initialize(requirement)
  @requirement = requirement
  @category = requirement['category']
  @commands = requirement['commands']
  @roles = requirement['roles']
end

Instance Attribute Details

#categoryObject (readonly)

Returns the value of attribute category.



6
7
8
# File 'lib/seira/teleport/role_requirements.rb', line 6

def category
  @category
end

#commandsObject (readonly)

Returns the value of attribute commands.



6
7
8
# File 'lib/seira/teleport/role_requirements.rb', line 6

def commands
  @commands
end

#rolesObject (readonly)

Returns the value of attribute roles.



6
7
8
# File 'lib/seira/teleport/role_requirements.rb', line 6

def roles
  @roles
end

Instance Method Details

#<=>(other) ⇒ Object

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/seira/teleport/role_requirements.rb', line 19

def <=>(other)
  raise ArgumentError, 'Cannot compare different categories' if category != other.category
  
  if commands.nil?
    return -1
  elsif other.commands.nil?
    return 1
  end

  commands.length <=> other.commands.length
end

#matches?(category, command) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/seira/teleport/role_requirements.rb', line 15

def matches?(category, command)
  @category == category && command_matches?(command)
end