Sha256: 595d03e4f7e6eedcf6d72100935b8e4dcd612783c6de6f33ebe860ca1dca827c
Contents?: true
Size: 1.23 KB
Versions: 1
Compression:
Stored size: 1.23 KB
Contents
# @author Kristian Mandrup # # Many role storage for storing roles as an Integer bitmask on the role subject # # @note all methods potentially operate directly on values in the data store # module Troles::Storage class BitMany < BaseMany # constructor # @param [Object] the role subject def initialize role_subject super end # display the roles as a list of symbols # see Troles::Marshaller::Bitmask # @return [Array<Symbol>] roles list def display_roles return [] if !ds_field_value? bitmask.read end def ds_field_value? ds_field_value > 0 end # saves the roles for the role subject in the data store # see Troles::Marshaller::Bitmask # @param [Array<Symbol>] roles list def set_roles *roles roles = roles.to_symbols_uniq return clear! if roles.empty? set_ds_field bitmask.write(roles.to_symbols) end # Clears the role state of the role subject def clear! set_ds_field 0 end # Sets role to default state def set_default_role! clear! end protected def bitmask @bitmask ||= bitmask_class.new role_subject end def bitmask_class Troles::Common::Marshaller::Bitmask end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
troles-0.6.1 | lib/troles/storage/bit_many.rb |