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

Instance Method Summary collapse

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.

Parameters:

  • base (Module)

    the module that has extended Bandoleer



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.

Parameters:

  • key (Symbol)

    the entry to resolve



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.

Parameters:

  • files (String, Symbol, Array)

    filename(s) to be registered



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.

Parameters:

  • elixirs (Hash)

    file keys with their associated values



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

#keysArray Also known as: equipped

Returns list of keys for registered entries.

Returns:

  • (Array)

    list of keys for registered entries



16
# File 'lib/bandoleer.rb', line 16

def_delegators :pockets, :[], :keys, :method_missing

#open_vialsObject

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

#pocketsCanister

Returns the stored Canister instance.

Returns:

  • (Canister)

    the stored Canister instance



33
34
35
# File 'lib/bandoleer.rb', line 33

def pockets
  @pockets ||= Canister.new
end