Class: Transproc::Store Private

Inherits:
Object
  • Object
show all
Defined in:
lib/transproc/store.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Immutable collection of named procedures from external modules

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(methods = {}) ⇒ Store

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Store



24
25
26
27
# File 'lib/transproc/store.rb', line 24

def initialize(methods = {})
  @methods = methods.dup.freeze
  freeze
end

Instance Attribute Details

#methodsHash (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The associated list of imported procedures

Returns:

  • (Hash)

    The associated list of imported procedures



13
14
15
# File 'lib/transproc/store.rb', line 13

def methods
  @methods
end

Instance Method Details

#fetch(key) ⇒ Proc

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a procedure by its key in the collection

Parameters:

  • key (Symbol)

Returns:

  • (Proc)


35
36
37
# File 'lib/transproc/store.rb', line 35

def fetch(key)
  methods.fetch(key.to_sym)
end

#import(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Imports proc(s) to the collection from another module



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/transproc/store.rb', line 43

def import(*args)
  first = args.first
  return import_all(first) if first.instance_of?(Module)

  opts   = args.pop
  source = opts.fetch(:from)
  rename = opts.fetch(:as) { first.to_sym }

  return import_methods(source, args) if args.count > 1
  import_method(source, first, rename)
end