Sha256: ac6630b0be1bae8966c9ecbce7838eb7ae813cd7d97f882cb9f60301e76df84a
Contents?: true
Size: 1.56 KB
Versions: 1
Compression:
Stored size: 1.56 KB
Contents
require 'jerry/version' require 'jerry/config' # Inversion of Control container. # # This class is in charge of bootstrapping your application. This is done by defining {Jerry::Config configs}. # # @example # class MyConfig < Jerry::Config # component(:app) { MyApp.new } # end # jerry = Jerry.new MyConfig.new # jerry.rig :app #=> #<MyApp:...> class Jerry # Indicated that an error occurred while rigging a component class RigError < StandardError; end # @param [Jerry::Config] configs Configs used to rig components. Multiple config can be given. If two configs # define the same component, the later config will have priority. def initialize(*configs) @index = {} configs.each { |config| self << config } end # Load a config # # @param [Jerry::Config] config Config to be loaded. If the loaded config defines a component already defined # by another config, the component from the new config will take priority. def <<(config) components = config.components components.each { |component| @index[component] = config } config.jerry = self end # Rigs a component # # @param [Symbol] component Component to rig. # @return The component requested # @raise [Jerry::RigError] when the requested component does not exist def rig(component) raise RigError, "could not find component #{component}" unless knows? component @index[component].public_send component end # Checks if a component exists # # @param [Symbol] component component to check def knows?(component) @index.has_key? component end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
jerry-1.0.1 | lib/jerry.rb |