Class: Admission::Privilege
- Inherits:
-
Object
- Object
- Admission::Privilege
- Defined in:
- lib/admission/privilege.rb
Constant Summary collapse
- RESERVED_ID =
:'^'.freeze
- TOP_LEVEL_KEY =
RESERVED_ID
- BASE_LEVEL_NAME =
:base
- SEPARATOR =
'-'.freeze
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#hash ⇒ Object
readonly
Returns the value of attribute hash.
-
#inherited ⇒ Object
readonly
Returns the value of attribute inherited.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #dup_with_context(context = nil) ⇒ Object
- #eql?(other) ⇒ Boolean
- #eql_or_inherits?(sought) ⇒ Boolean
- #inherits_from(*privileges) ⇒ Object
-
#initialize(name, level = nil) ⇒ Privilege
constructor
A new instance of Privilege.
- #inspect ⇒ Object
- #text_key ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, level = nil) ⇒ Privilege
Returns a new instance of Privilege.
11 12 13 14 15 |
# File 'lib/admission/privilege.rb', line 11 def initialize name, level=nil @name = name.to_sym @level = level ? level.to_sym : BASE_LEVEL_NAME @hash = [@name, @level].hash end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
9 10 11 |
# File 'lib/admission/privilege.rb', line 9 def context @context end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
8 9 10 |
# File 'lib/admission/privilege.rb', line 8 def hash @hash end |
#inherited ⇒ Object (readonly)
Returns the value of attribute inherited.
9 10 11 |
# File 'lib/admission/privilege.rb', line 9 def inherited @inherited end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
8 9 10 |
# File 'lib/admission/privilege.rb', line 8 def level @level end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/admission/privilege.rb', line 8 def name @name end |
Class Method Details
.split_text_key(value) ⇒ Object
42 43 44 |
# File 'lib/admission/privilege.rb', line 42 def self.split_text_key value return value.split(SEPARATOR) end |
Instance Method Details
#dup_with_context(context = nil) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/admission/privilege.rb', line 21 def dup_with_context context=nil return self if context.nil? with_context = dup with_context.instance_variable_set :@context, context with_context end |
#eql?(other) ⇒ Boolean
28 29 30 |
# File 'lib/admission/privilege.rb', line 28 def eql? other hash == other.hash end |
#eql_or_inherits?(sought) ⇒ Boolean
32 33 34 35 36 |
# File 'lib/admission/privilege.rb', line 32 def eql_or_inherits? sought return true if eql? sought return false unless inherited inherited.any?{|pi| pi.eql_or_inherits? sought} end |
#inherits_from(*privileges) ⇒ Object
17 18 19 |
# File 'lib/admission/privilege.rb', line 17 def inherits_from *privileges @inherited = privileges end |
#inspect ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/admission/privilege.rb', line 46 def inspect "#<#{[ 'Privilege', "key=#{text_key}", (inherited && "inherited=[#{inherited.map(&:text_key).join ','}]") ].compact.join ' '}>" end |
#text_key ⇒ Object
38 39 40 |
# File 'lib/admission/privilege.rb', line 38 def text_key @text_key ||= level == BASE_LEVEL_NAME ? name.to_s : "#{name}#{SEPARATOR}#{level}" end |
#to_s ⇒ Object
54 55 56 57 58 59 |
# File 'lib/admission/privilege.rb', line 54 def to_s [ "privilege #{text_key}", (context && ", context #{context}") ].join '' end |