Class: Admission::Index
- Inherits:
-
Object
- Object
- Admission::Index
- Defined in:
- lib/admission/index.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #allow(*add_items, **add_children) ⇒ Object
- #allowed?(*path) ⇒ Boolean
-
#initialize ⇒ Index
constructor
A new instance of Index.
- #to_a ⇒ Object
Constructor Details
#initialize ⇒ Index
Returns a new instance of Index.
5 6 7 8 |
# File 'lib/admission/index.rb', line 5 def initialize @items = [] @children = {} end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
3 4 5 |
# File 'lib/admission/index.rb', line 3 def children @children end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
3 4 5 |
# File 'lib/admission/index.rb', line 3 def items @items end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
35 36 37 38 39 40 41 42 |
# File 'lib/admission/index.rb', line 35 def == other case other when Array to_a.eql? other else super end end |
#allow(*add_items, **add_children) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/admission/index.rb', line 10 def allow *add_items, **add_children @items |= add_items.flatten.map(&:to_sym) add_children.each do |key, list| child = Admission::Index.new child.allow *list children[key] = child end self end |
#allowed?(*path) ⇒ Boolean
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/admission/index.rb', line 22 def allowed? *path item, *path = path item = item.to_sym if path.empty? items.include? item else child = children[item] child ? child.allowed?(*path) : false end end |
#to_a ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/admission/index.rb', line 45 def to_a result_list = items.dup unless children.empty? result_children = children.inject Hash.new do |h, (key, index)| h[key] = index.to_a h end result_list.push result_children end result_list end |