Class: Bcome::Node::Resources::Base
- Inherits:
-
Object
- Object
- Bcome::Node::Resources::Base
- Includes:
- Enumerable
- Defined in:
- lib/objects/node/resources/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#nodes ⇒ Object
readonly
Returns the value of attribute nodes.
Instance Method Summary collapse
- #<<(node) ⇒ Object
- #active ⇒ Object
- #clear! ⇒ Object
- #disable(identifier) ⇒ Object
- #disable! ⇒ Object
- #do_disable(identifier) ⇒ Object
- #do_enable(identifier) ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #enable(identifier) ⇒ Object
- #enable! ⇒ Object
- #first ⇒ Object
- #for_identifier(identifier) ⇒ Object
- #has_active_nodes? ⇒ Boolean
-
#initialize(*_params) ⇒ Base
constructor
A new instance of Base.
- #is_active_resource?(resource) ⇒ Boolean
- #should_rename_initial_duplicate? ⇒ Boolean
- #size ⇒ Object
Constructor Details
#initialize(*_params) ⇒ Base
Returns a new instance of Base.
9 10 11 12 |
# File 'lib/objects/node/resources/base.rb', line 9 def initialize(*_params) @nodes = [] @disabled_resources = [] end |
Instance Attribute Details
#nodes ⇒ Object (readonly)
Returns the value of attribute nodes.
7 8 9 |
# File 'lib/objects/node/resources/base.rb', line 7 def nodes @nodes end |
Instance Method Details
#<<(node) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/objects/node/resources/base.rb', line 18 def <<(node) existing_node = for_identifier(node.identifier) if existing_node = "#{node.identifier} is not unique within namespace #{node.parent.namespace}" raise Bcome::Exception::NodeIdentifiersMustBeUnique, end @nodes << node end |
#active ⇒ Object
77 78 79 |
# File 'lib/objects/node/resources/base.rb', line 77 def active @nodes - @disabled_resources end |
#clear! ⇒ Object
31 32 33 |
# File 'lib/objects/node/resources/base.rb', line 31 def clear! @disabled_resources = [] end |
#disable(identifier) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/objects/node/resources/base.rb', line 58 def disable(identifier) resource = for_identifier(identifier) raise Bcome::Exception::NoNodeNamedByIdentifier, identifier unless resource @disabled_resources << resource unless @disabled_resources.include?(resource) end |
#disable! ⇒ Object
54 55 56 |
# File 'lib/objects/node/resources/base.rb', line 54 def disable! @disabled_resources = @nodes end |
#do_disable(identifier) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/objects/node/resources/base.rb', line 36 def do_disable(identifier) if identifier.is_a?(Array) identifier.each { |id| disable(id) } else disable(identifier) end nil end |
#do_enable(identifier) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/objects/node/resources/base.rb', line 45 def do_enable(identifier) if identifier.is_a?(Array) identifier.each { |id| enable(id) } else enable(identifier) end nil end |
#each ⇒ Object
14 15 16 |
# File 'lib/objects/node/resources/base.rb', line 14 def each @nodes.each { |node| yield(node) } end |
#empty? ⇒ Boolean
90 91 92 |
# File 'lib/objects/node/resources/base.rb', line 90 def empty? @nodes.empty? end |
#enable(identifier) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/objects/node/resources/base.rb', line 65 def enable(identifier) resource = for_identifier(identifier) raise Bcome::Exception::NoNodeNamedByIdentifier, identifier unless resource @disabled_resources -= [resource] end |
#enable! ⇒ Object
34 35 36 |
# File 'lib/objects/node/resources/base.rb', line 34 def clear! @disabled_resources = [] end |
#first ⇒ Object
102 103 104 |
# File 'lib/objects/node/resources/base.rb', line 102 def first @nodes.first end |
#for_identifier(identifier) ⇒ Object
85 86 87 88 |
# File 'lib/objects/node/resources/base.rb', line 85 def for_identifier(identifier) resource = @nodes.select { |node| node.identifier == identifier }.last resource end |
#has_active_nodes? ⇒ Boolean
94 95 96 |
# File 'lib/objects/node/resources/base.rb', line 94 def has_active_nodes? active.any? end |
#is_active_resource?(resource) ⇒ Boolean
81 82 83 |
# File 'lib/objects/node/resources/base.rb', line 81 def is_active_resource?(resource) active.include?(resource) end |
#should_rename_initial_duplicate? ⇒ Boolean
27 28 29 |
# File 'lib/objects/node/resources/base.rb', line 27 def should_rename_initial_duplicate? false end |
#size ⇒ Object
98 99 100 |
# File 'lib/objects/node/resources/base.rb', line 98 def size @nodes.size end |