Sha256: d90d4c17b1bb895e83e26d132e94060862aff00b1b535875da915d323d27f3d0

Contents?: true

Size: 864 Bytes

Versions: 3

Compression:

Stored size: 864 Bytes

Contents

module Formol
  module Permissions
    class Profiles
      def initialize
        @profiles = {}
      end
      
      def self.from_hash(hash)
        p = Profiles.new
        
        hash.each do |name, opts|
          p.add_profile(name, opts)
        end
        
        p
      end

      def add_right_to_profile(name, right)
        @profiles[name.to_sym] << right.to_sym
      end
      
      def delete_right_from_profile(name, right)
        @profiles[name.to_sym].delete(right)
      end

      def profiles
        @profiles.keys
      end

      def add_profile(name, opts = {})
        r = []

        r += self[opts[:extends]].rights if opts[:extends]
        r += opts[:rights] if opts[:rights]

        @profiles[name.to_sym] = Profile.new(name, r.uniq)
      end

      def [](name)
        @profiles[name.to_sym]
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
formol-0.0.6 lib/formol/permissions/profiles.rb
formol-0.0.5 lib/formol/permissions/profiles.rb
formol-0.0.4 lib/formol/permissions/profiles.rb