Class: SparkleFormation::SparkleCollection
- Defined in:
- lib/sparkle_formation/sparkle_collection.rb,
lib/sparkle_formation/sparkle_collection/rainbow.rb
Overview
add unmemoize behavior on collection modification to prevent
Provides a collection of sparkles leak on long running processes with long lasting collections
Defined Under Namespace
Classes: Rainbow
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.
-
#apply(collection) ⇒ self
Apply collection settings to this collection.
- #components ⇒ Smash
- #dynamics ⇒ Smash
- #empty? ⇒ TrueClass, FalseClass
-
#get(type, name) ⇒ 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
14 15 16 17 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 14 def initialize(*_) @root = nil @sparkles = [] end |
Instance Method Details
#add_sparkle(sparkle, precedence = :high) ⇒ self
Add new sparkle to collection
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 43 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 |
#apply(collection) ⇒ self
will overwrite existing set packs
Apply collection settings to this collection
24 25 26 27 28 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 24 def apply(collection) @root = collection.sparkles.last @sparkles = collection.sparkles.slice(0, collection.sparkles.length - 1) || [] self end |
#components ⇒ Smash
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 80 def components memoize("components_#{checksum}") do Smash.new.tap do |hsh| sparkles.each do |sprkl| sprkl.components.each_pair do |c_name, c_value| hsh[c_name] ||= Rainbow.new(c_name, :component) hsh[c_name].add_layer(c_value) end end end end end |
#dynamics ⇒ Smash
94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 94 def dynamics memoize("dynamics_#{checksum}") do Smash.new.tap do |hsh| sparkles.each do |sprkl| sprkl.dynamics.each_pair do |c_name, c_value| hsh[c_name] ||= Rainbow.new(c_name, :dynamic) hsh[c_name].add_layer(c_value) end end end end end |
#empty? ⇒ TrueClass, FalseClass
75 76 77 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 75 def empty? size == 0 end |
#get(type, name) ⇒ Smash
Request item from the store
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 138 def get(type, name) type_name = Sparkle::TYPES[type.to_s] unless(type_name) raise ArgumentError.new "Unknown file type requested from collection `#{type}`" end result = nil error = nil result = send(type_name)[name] if(result.nil? && type_name == 'templates') t_direct = sparkles.map do |pack| begin pack.get(:template, name) rescue Error::NotFound end end.compact.last if(t_direct) result = send(type_name)[t_direct[:name]] end end unless(result) error_klass = Error::NotFound.const_get( Bogo::Utility.camel(type) ) raise error_klass.new(:name => name) end result end |
#registries ⇒ Smash
108 109 110 111 112 113 114 115 116 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 108 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
59 60 61 62 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 59 def remove_sparkle(sparkle) @sparkles.delete(sparkle) self end |
#set_root(sparkle) ⇒ self
Set the root sparkle which forces highest precedence
34 35 36 37 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 34 def set_root(sparkle) @root = sparkle self end |
#size ⇒ Integer
70 71 72 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 70 def size sparkles.size end |
#sparkle_at(idx) ⇒ Sparkle, NilClass
65 66 67 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 65 def sparkle_at(idx) sparkles.at(idx) end |
#templates ⇒ Smash
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 119 def templates memoize("templates_#{checksum}") do Smash.new.tap do |hsh| sparkles.each do |sprkl| sprkl.templates.each_pair do |c_name, c_value| hsh[c_name] ||= Rainbow.new(c_name, :template) hsh[c_name].add_layer(c_value) end end end end end |