Class: Admission::Privilege
- Inherits:
-
Object
- Object
- Admission::Privilege
- Defined in:
- lib/admission/privilege.rb
Defined Under Namespace
Classes: OrderDefiner
Constant Summary collapse
- RESERVED_ID =
:'^'
- TOP_LEVEL_KEY =
RESERVED_ID
- BASE_LEVEL_NAME =
:base
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
- .define_order(&block) ⇒ Object
- .get_from_order(index, name, level = nil) ⇒ Object
- .order_to_array(index) ⇒ Object
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.
10 11 12 13 14 15 16 |
# File 'lib/admission/privilege.rb', line 10 def initialize name, level=nil name = name.to_sym @name = name level = level ? level.to_sym : BASE_LEVEL_NAME @level = level @hash = [name, level].hash end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
8 9 10 |
# File 'lib/admission/privilege.rb', line 8 def context @context end |
#hash ⇒ Object (readonly)
Returns the value of attribute hash.
7 8 9 |
# File 'lib/admission/privilege.rb', line 7 def hash @hash end |
#inherited ⇒ Object (readonly)
Returns the value of attribute inherited.
8 9 10 |
# File 'lib/admission/privilege.rb', line 8 def inherited @inherited end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
7 8 9 |
# File 'lib/admission/privilege.rb', line 7 def level @level end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/admission/privilege.rb', line 7 def name @name end |
Class Method Details
.define_order(&block) ⇒ Object
58 59 60 |
# File 'lib/admission/privilege.rb', line 58 def self.define_order &block Admission::Privilege::OrderDefiner.define &block end |
.get_from_order(index, name, level = nil) ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/admission/privilege.rb', line 62 def self.get_from_order index, name, level=nil levels = index[name.to_sym] || return if level && !level.empty? levels[level.to_sym] else levels[Admission::Privilege::BASE_LEVEL_NAME] end end |
.order_to_array(index) ⇒ Object
71 72 73 |
# File 'lib/admission/privilege.rb', line 71 def self.order_to_array index index.values.map(&:values).flatten.uniq end |
Instance Method Details
#dup_with_context(context = nil) ⇒ Object
22 23 24 25 26 27 |
# File 'lib/admission/privilege.rb', line 22 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
29 30 31 |
# File 'lib/admission/privilege.rb', line 29 def eql? other hash == other.hash end |
#eql_or_inherits?(sought) ⇒ Boolean
33 34 35 36 37 |
# File 'lib/admission/privilege.rb', line 33 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
18 19 20 |
# File 'lib/admission/privilege.rb', line 18 def inherits_from *privileges @inherited = privileges end |
#inspect ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/admission/privilege.rb', line 43 def inspect "#<#{[ 'Privilege', "key=#{text_key}", (inherited && "inherited=[#{inherited.map(&:text_key).join ','}]") ].compact.join ' '}>" end |
#text_key ⇒ Object
39 40 41 |
# File 'lib/admission/privilege.rb', line 39 def text_key level == BASE_LEVEL_NAME ? name.to_s : "#{name}-#{level}" end |
#to_s ⇒ Object
51 52 53 54 55 56 |
# File 'lib/admission/privilege.rb', line 51 def to_s [ "privilege #{text_key}", (context && ", context #{context}") ].join '' end |