Class: Dry::Transformer::Store Private

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/transformer/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

Class Method Summary collapse

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



14
15
16
# File 'lib/dry/transformer/store.rb', line 14

def methods
  @methods
end

Class Method Details

.contain?(key) ⇒ Boolean

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 wether the collection contains such procedure by its key

Parameters:

  • key (Symbol)

Returns:

  • (Boolean)


46
47
48
# File 'lib/dry/transformer/store.rb', line 46

def contain?(key)
  methods.key?(key)
end

.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)


36
37
38
# File 'lib/dry/transformer/store.rb', line 36

def fetch(key)
  methods.fetch(key)
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



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/dry/transformer/store.rb', line 65

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

.initialize(methods = {}) ⇒ 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.



25
26
27
28
# File 'lib/dry/transformer/store.rb', line 25

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

.register(name, fn = nil, &block) ⇒ 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.

store.register(:to_json) { |v| v.to_json }



57
58
59
# File 'lib/dry/transformer/store.rb', line 57

def register(name, fn = nil, &block)
  self.class.new(methods.merge(name => fn || block))
end