Class: SparkleFormation::SparkleCollection
- Defined in:
- lib/sparkle_formation/sparkle_collection.rb,
lib/sparkle_formation/sparkle_collection/rainbow.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
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.
- #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
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 32 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
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 69 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
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 83 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
64 65 66 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 64 def empty? size == 0 end |
#get(type, name) ⇒ Smash
Request item from the store
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 127 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] unless(result) error_klass = Error::NotFound.const_get( Bogo::Utility.camel(type) ) raise error_klass.new(:name => name) end result end |
#registries ⇒ Smash
97 98 99 100 101 102 103 104 105 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 97 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
48 49 50 51 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 48 def remove_sparkle(sparkle) @sparkles.delete(sparkle) self end |
#set_root(sparkle) ⇒ self
Set the root sparkle which forces highest precedence
23 24 25 26 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 23 def set_root(sparkle) @root = sparkle self end |
#size ⇒ Integer
59 60 61 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 59 def size sparkles.size end |
#sparkle_at(idx) ⇒ Sparkle, NilClass
54 55 56 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 54 def sparkle_at(idx) sparkles.at(idx) end |
#templates ⇒ Smash
108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/sparkle_formation/sparkle_collection.rb', line 108 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 |