Module: Bandoleer
- Extended by:
- Forwardable
- Includes:
- Conversions
- Defined in:
- lib/bandoleer.rb,
lib/bandoleer/cli.rb,
lib/bandoleer/version.rb,
lib/bandoleer/outfitter.rb,
lib/bandoleer/erb_helper.rb,
lib/bandoleer/conversions.rb
Overview
Wrapper for Canister, a container gem used to register dependencies. Provides helper methods for referencing constants from files.
Defined Under Namespace
Modules: Conversions, ErbHelper Classes: CLI, Outfitter
Constant Summary collapse
- VERSION =
Current gem version
'0.2.3'
Class Method Summary collapse
-
.extended(base) ⇒ Object
Ensure vials are resolved when a module extending Bandoleer is included.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Resolve a registered entry from Canister.
-
#equip(files) ⇒ Object
Register a single file or an Array of filenames.
-
#equip_custom(elixirs) ⇒ Object
Register a Hash of filenames with custom actions.
-
#keys ⇒ Array
(also: #equipped)
List of keys for registered entries.
-
#open_vials ⇒ Object
Resolve all of the registered entries at once.
-
#pockets ⇒ Canister
The stored Canister instance.
Methods included from Conversions
#klass_to_snake, #snake_to_camel
Class Method Details
.extended(base) ⇒ Object
Ensure vials are resolved when a module extending Bandoleer is included.
21 22 23 24 25 |
# File 'lib/bandoleer.rb', line 21 def self.extended( base ) base_dir = File.dirname(const_source_location(base.name).first) base.instance_variable_set(:@klass_dir, base_dir) base.define_singleton_method(:included) {|_base| open_vials } end |
Instance Method Details
#[](key) ⇒ Object
Resolve a registered entry from Canister.
16 |
# File 'lib/bandoleer.rb', line 16 def_delegators :pockets, :[], :keys, :method_missing |
#equip(files) ⇒ Object
Register a single file or an Array of filenames. Assumes that all files are ruby files inside a folder named Klass.name, and that they all define a constant matching the name of the file.
41 42 43 44 45 46 47 48 |
# File 'lib/bandoleer.rb', line 41 def equip( files ) [files].flatten.each do |vial| pockets.register(vial) do retrieve vial const_get snake_to_camel(vial.to_s) end end end |
#equip_custom(elixirs) ⇒ Object
Register a Hash of filenames with custom actions.
52 53 54 55 56 57 58 59 |
# File 'lib/bandoleer.rb', line 52 def equip_custom( elixirs ) elixirs.each do |vial, contents| pockets.register(vial.downcase) do retrieve vial contents end end end |
#keys ⇒ Array Also known as: equipped
Returns list of keys for registered entries.
16 |
# File 'lib/bandoleer.rb', line 16 def_delegators :pockets, :[], :keys, :method_missing |
#open_vials ⇒ Object
Resolve all of the registered entries at once.
28 29 30 |
# File 'lib/bandoleer.rb', line 28 def open_vials equipped.each {|vial| pockets.resolve vial } end |
#pockets ⇒ Canister
Returns the stored Canister instance.
33 34 35 |
# File 'lib/bandoleer.rb', line 33 def pockets @pockets ||= Canister.new end |