Sha256: 63ac9dd06890e7d0fc7ba97a05620eecfcd350d616b176c2dbef5b6f89323b4a

Contents?: true

Size: 997 Bytes

Versions: 11

Compression:

Stored size: 997 Bytes

Contents

# Defines sets of privileges
#
# To create a new set: PrivilegeSet.add :set_name, "Some comment on what this
# set does"
#
# To retrieve a privilegeset, use the sets attribute. This is a Hash containing
# PrivilegeSetRecords. Usage: PrivilegeSet.sets(:set_name). If the PrivilegeSet
# already exists, an ArgumentError is thrown stating the set was already
# defined.
class Cbac::PrivilegeSet
  class << self
    # Hash containing all the PrivilegeSetRecords
    attr_reader :sets

    # Create a new PrivilegeSet
    def add(symbol, comment)
      # initialize variables (if applicable)
      @sets = Hash.new if @sets.nil?
      # check for double creation
      raise ArgumentError, "CBAC: PrivilegeSet was already defined: #{symbol.to_s}" if @sets.include?(symbol)
      # Create record if privilege set doesn't exist
      record = Cbac::PrivilegeSetRecord.find_or_create_by_name(symbol.to_s)
      record.set_comment(comment)
      record.save

      @sets[symbol] = record
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
cbac-0.6.10 lib/cbac/privilege_set.rb
cbac-0.6.9 lib/cbac/privilege_set.rb
cbac-0.6.8 lib/cbac/privilege_set.rb
cbac-0.6.7 lib/cbac/privilege_set.rb
cbac-0.6.5 lib/cbac/privilege_set.rb
cbac-0.6.4 lib/cbac/privilege_set.rb
cbac-0.6.2 lib/cbac/privilege_set.rb
cbac-0.5.4 lib/cbac/privilege_set.rb
cbac-0.5.3 lib/cbac/privilege_set.rb
cbac-0.5.2 lib/cbac/privilege_set.rb
cbac-0.5.1 lib/cbac/privilege_set.rb