Class: SparkleFormation::SparkleCollection
- Defined in:
- lib/sparkle_formation/sparkle_collection.rb
Overview
TODO:
add unmemoize behavior on collection modification to prevent
Provides a collection of sparkles leak on long running processes with long lasting collections
Constant Summary
Constants inherited from Sparkle
SparkleFormation::Sparkle::DIRS, SparkleFormation::Sparkle::TYPES, SparkleFormation::Sparkle::VALID_ROOT_DIRS
Instance Attribute Summary
Attributes inherited from Sparkle
Instance Method Summary collapse
-
#add_sparkle(sparkle, precedence = :high) ⇒ self
Add new sparkle to collection.
- #components ⇒ Smash
- #dynamics ⇒ Smash
- #empty? ⇒ TrueClass, FalseClass
-
#get(*args) ⇒ Smash
Request item from the store.
-
#initialize(*_) ⇒ self
constructor
Create a new collection of sparkles.
- #registries ⇒ Smash
-
#remove_sparkle(sparkle) ⇒ self
Remove sparkle from collection.
-
#set_root(sparkle) ⇒ self
Set the root sparkle which forces highest precedence.
- #size ⇒ Integer
- #sparkle_at(idx) ⇒ Sparkle, NilClass
- #templates ⇒ Smash
Methods inherited from Sparkle
#eval_wrapper, #inspect, path, register!
Constructor Details
#initialize(*_) ⇒ self
Create a new collection of sparkles
12 13 14 15 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 12 def initialize(*_) @root = nil @sparkles = [] end |
Instance Method Details
#add_sparkle(sparkle, precedence = :high) ⇒ self
Add new sparkle to collection
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 30 def add_sparkle(sparkle, precedence=:high) unless(sparkle.is_a?(Sparkle)) raise TypeError.new "Expected type `SparkleFormation::Sparkle` but received `#{sparkle.class}`!" end if(precedence == :high) @sparkles.push(sparkle).uniq! else @sparkles.unshift(sparkle).uniq! end self end |
#components ⇒ Smash
67 68 69 70 71 72 73 74 75 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 67 def components memoize("components_#{checksum}") do Smash.new.tap do |hsh| sparkles.each do |sprkl| hsh.merge!(sprkl.components) end end end end |
#dynamics ⇒ Smash
78 79 80 81 82 83 84 85 86 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 78 def dynamics memoize("dynamics_#{checksum}") do Smash.new.tap do |hsh| sparkles.each do |sprkl| hsh.merge!(sprkl.dynamics) end end end end |
#empty? ⇒ TrueClass, FalseClass
62 63 64 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 62 def empty? size == 0 end |
#get(*args) ⇒ Smash
Request item from the store
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 116 def get(*args) result = nil error = nil sparkles.each do |sprkl| begin result = sprkl.get(*args) rescue Error::NotFound => error end end if(result) result else raise error end end |
#registries ⇒ Smash
89 90 91 92 93 94 95 96 97 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 89 def registries memoize("registries_#{checksum}") do Smash.new.tap do |hsh| sparkles.each do |sprkl| hsh.merge!(sprkl.registries) end end end end |
#remove_sparkle(sparkle) ⇒ self
Remove sparkle from collection
46 47 48 49 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 46 def remove_sparkle(sparkle) @sparkles.delete(sparkle) self end |
#set_root(sparkle) ⇒ self
Set the root sparkle which forces highest precedence
21 22 23 24 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 21 def set_root(sparkle) @root = sparkle self end |
#size ⇒ Integer
57 58 59 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 57 def size sparkles.size end |
#sparkle_at(idx) ⇒ Sparkle, NilClass
52 53 54 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 52 def sparkle_at(idx) sparkles.at(idx) end |
#templates ⇒ Smash
100 101 102 103 104 105 106 107 108 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 100 def templates memoize("templates_#{checksum}") do Smash.new.tap do |hsh| sparkles.each do |sprkl| hsh.merge!(sprkl.templates) end end end end |