Class: SparkleFormation::Sparkle
- Inherits:
-
Object
- Object
- SparkleFormation::Sparkle
- Includes:
- Bogo::Memoization
- Defined in:
- lib/sparkle_formation/sparkle.rb
Overview
Independent collection of SparkleFormation items
Direct Known Subclasses
Defined Under Namespace
Classes: EvalWrapper
Constant Summary collapse
- VALID_ROOT_DIRS =
Valid directories from cwd to set as root
[ 'sparkleformation', 'sfn', 'cloudformation', 'cfn', '.' ]
- DIRS =
Reserved directories
[ 'components', 'registry', 'dynamics' ]
- TYPES =
Valid types
Smash.new( 'component' => 'components', 'registry' => 'registries', 'dynamic' => 'dynamics', 'template' => 'templates' )
- @@_pack_registry =
Smash.new
Instance Attribute Summary collapse
-
#provider ⇒ Symbol
Provider.
-
#raw_data ⇒ Smash
readonly
Raw part data.
-
#root ⇒ String
readonly
Path to sparkle directories.
Class Method Summary collapse
-
.path(name) ⇒ String
Return the path to the SparkePack registered with the given name.
-
.register!(name = nil, path = nil) ⇒ Array<String:name, String:path>
Register a SparklePack for short name access.
Instance Method Summary collapse
- #components ⇒ Smash<name:block>
- #dynamics ⇒ Smash<name:block>
-
#eval_wrapper ⇒ Object
Wrapper for evaluating sfn files to store within sparkle container.
-
#get(type, name, target_provider = nil) ⇒ Smash
Request item from the store.
-
#initialize(args = {}) ⇒ self
constructor
Create new sparkle instance.
- #inspect ⇒ String
- #registries ⇒ Smash<name:block>
- #templates ⇒ Smash<name:path>
Constructor Details
#initialize(args = {}) ⇒ self
Create new sparkle instance
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/sparkle_formation/sparkle.rb', line 228 def initialize(args={}) if(args[:name]) @root = self.class.path(args[:name]) else @root = args.fetch(:root, locate_root) end if(@root != :none && !File.directory?(@root)) raise Errno::ENOENT.new("No such directory - #{@root}") end @raw_data = Smash.new( :dynamic => [], :component => [], :registry => [], :template => [] ) @provider = Bogo::Utility.snake(args.fetch(:provider, 'aws').to_s).to_sym @wrapper = eval_wrapper.new wrapper.part_data(raw_data) load_parts! unless @root == :none end |
Instance Attribute Details
#provider ⇒ Symbol
Returns provider.
219 220 221 |
# File 'lib/sparkle_formation/sparkle.rb', line 219 def provider @provider end |
#raw_data ⇒ Smash (readonly)
Returns raw part data.
217 218 219 |
# File 'lib/sparkle_formation/sparkle.rb', line 217 def raw_data @raw_data end |
#root ⇒ String (readonly)
Returns path to sparkle directories.
215 216 217 |
# File 'lib/sparkle_formation/sparkle.rb', line 215 def root @root end |
Class Method Details
.path(name) ⇒ String
Return the path to the SparkePack registered with the given name
172 173 174 175 176 177 178 |
# File 'lib/sparkle_formation/sparkle.rb', line 172 def path(name) if(@@_pack_registry[name]) @@_pack_registry[name] else raise KeyError.new "No pack registered with requested name: #{name}!" end end |
.register!(name = nil, path = nil) ⇒ Array<String:name, String:path>
Register a SparklePack for short name access
134 135 136 137 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 165 |
# File 'lib/sparkle_formation/sparkle.rb', line 134 def register!(name=nil, path=nil) unless(path) idx = caller.index do |item| item.end_with?("`register!'") end idx = idx ? idx.next : 0 # Trim from the end to determine path allowing windows paths # to not be improperly truncated file = caller[idx].split(':').reverse.drop(2).reverse.join(':') path = File.join(File.dirname(file), 'sparkleformation') unless(File.directory?(path)) path = nil end unless(name) name = File.basename(file) name.sub!(File.extname(name), '') end end unless(name) if(path) name = path.split(File::PATH_SEPARATOR)[-3].to_s end end unless(path) raise ArgumentError.new('No SparklePack path provided and failed to auto-detect!') end unless(name) raise ArgumentError.new('No SparklePack name provided and failed to auto-detect!') end @@_pack_registry[name] = path [name, path] end |
Instance Method Details
#components ⇒ Smash<name:block>
250 251 252 253 254 |
# File 'lib/sparkle_formation/sparkle.rb', line 250 def components memoize(:components) do Smash.new end end |
#dynamics ⇒ Smash<name:block>
257 258 259 260 261 |
# File 'lib/sparkle_formation/sparkle.rb', line 257 def dynamics memoize(:dynamics) do Smash.new end end |
#eval_wrapper ⇒ Object
Wrapper for evaluating sfn files to store within sparkle container
184 185 186 |
# File 'lib/sparkle_formation/sparkle.rb', line 184 def eval_wrapper Class.new(EvalWrapper) end |
#get(type, name, target_provider = nil) ⇒ Smash
Request item from the store
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/sparkle_formation/sparkle.rb', line 284 def get(type, name, target_provider=nil) unless(TYPES.keys.include?(type.to_s)) raise NameError.new "Invalid type requested (#{type})! Valid types: #{TYPES.keys.join(', ')}" end unless(target_provider) target_provider = provider end result = send(TYPES[type]).get(target_provider, name) if(result.nil? && TYPES[type] == 'templates') result = ( send(TYPES[type]).fetch(target_provider, Smash.new).detect{|_, v| name = name.to_s short_name = v[:path].sub(%r{#{Regexp.escape(root)}/?}, '') v[:path] == name || short_name == name || short_name.sub('.rb', '').gsub(File::SEPARATOR, '__').tr('-', '_') == name || v[:path].end_with?(name) } || [] ).last end unless(result) klass = Error::NotFound.const_get(type.capitalize) raise klass.new("No #{type} registered with requested name (#{name})!", :name => name) end result end |
#inspect ⇒ String
312 313 314 |
# File 'lib/sparkle_formation/sparkle.rb', line 312 def inspect "<SparkleFormation::Sparkle [root: #{root.inspect}]>" end |
#registries ⇒ Smash<name:block>
264 265 266 267 268 |
# File 'lib/sparkle_formation/sparkle.rb', line 264 def registries memoize(:registries) do Smash.new end end |
#templates ⇒ Smash<name:path>
271 272 273 274 275 |
# File 'lib/sparkle_formation/sparkle.rb', line 271 def templates memoize(:templates) do Smash.new end end |