Sha256: e0e9a9d679f3a17c311f6cc068710535c2e0b1ad30126dbfbf54ce8132d211d0

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

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

3 entries across 3 versions & 1 rubygems

Version Path
cbac-0.6.3 lib/cbac/privilege_set.rb
cbac-0.6.1 lib/cbac/privilege_set.rb
cbac-0.6.0 lib/cbac/privilege_set.rb