Sha256: a7059be7c093b8c28f0d89820337f06b7f7bb0177657e5da1a9ed2541dee92a6
Contents?: true
Size: 966 Bytes
Versions: 2
Compression:
Stored size: 966 Bytes
Contents
module Seira module Teleport class RoleRequirement include Comparable attr_reader :commands, :category, :role def initialize(requirement) @requirement = requirement @category = requirement['category'] @commands = requirement['commands'] @role = requirement['role'] end def matches?(category, command) @category == category && command_matches?(command) end 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 private def command_matches?(command) return false if command == 'help' return true if @requirement['commands'].nil? @requirement['commands'].include?(command) end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
seira-0.8.1 | lib/seira/teleport/role_requirements.rb |
seira-0.8.0 | lib/seira/teleport/role_requirements.rb |