Module: Metaractor

Defined in:
lib/metaractor/parameters.rb,
lib/metaractor.rb,
lib/metaractor/spec.rb,
lib/metaractor/errors.rb,
lib/metaractor/version.rb,
lib/metaractor/namespace.rb,
lib/metaractor/organizer.rb,
lib/metaractor/handle_errors.rb,
lib/metaractor/chain_failures.rb,
lib/metaractor/context_errors.rb,
lib/metaractor/failure_output.rb,
lib/metaractor/context_has_key.rb,
lib/metaractor/context_validity.rb,
lib/metaractor/run_with_context.rb,
lib/metaractor/fail_from_context.rb

Overview

Special thanks to the ‘hashie` and `active_attr` gems for code and inspiration.

Defined Under Namespace

Modules: ChainFailures, ContextErrors, ContextHasKey, ContextValidity, FailFromContext, FailureOutput, HandleErrors, Namespace, Organizer, Parameters, RunWithContext, Spec Classes: Error, Errors, InvalidError

Constant Summary collapse

VERSION =
"3.3.4"

Class Method Summary collapse

Class Method Details

.clear_types!Object



90
91
92
# File 'lib/metaractor.rb', line 90

def self.clear_types!
  @types = {}
end

.configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (Metaractor)

    the object that the method was called on



32
33
34
# File 'lib/metaractor.rb', line 32

def self.configure
  yield self
end

.default_hash_formatterObject



70
71
72
# File 'lib/metaractor.rb', line 70

def self.default_hash_formatter
  ->(hash) { hash.inspect }
end

.default_modulesObject



44
45
46
47
48
49
50
51
52
# File 'lib/metaractor.rb', line 44

def self.default_modules
  [
    {module: Metaractor::HandleErrors, method: :include},
    {module: Metaractor::Parameters, method: :include},
    {module: Metaractor::RunWithContext, method: :include},
    {module: Metaractor::ChainFailures, method: :include},
    {module: Metaractor::Namespace, method: :include}
  ]
end

.format_hash(hash) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/metaractor.rb', line 62

def self.format_hash(hash)
  if @hash_formatter.nil?
    @hash_formatter = default_hash_formatter
  end

  @hash_formatter.call(hash)
end

.hash_formatterObject



74
75
76
# File 'lib/metaractor.rb', line 74

def self.hash_formatter
  @hash_formatter
end

.hash_formatter=(callable) ⇒ Object



78
79
80
# File 'lib/metaractor.rb', line 78

def self.hash_formatter=(callable)
  @hash_formatter = callable
end

.include_module(mod) ⇒ Object



54
55
56
# File 'lib/metaractor.rb', line 54

def self.include_module(mod)
  modules << {module: mod, method: :include}
end

.included(base) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/metaractor.rb', line 18

def self.included(base)
  base.class_eval do
    include Interactor
    Metaractor.modules.each do |hsh|
      case hsh[:method]
      when :include
        include hsh[:module]
      when :prepend
        prepend hsh[:module]
      end
    end
  end
end

.modulesObject



36
37
38
# File 'lib/metaractor.rb', line 36

def self.modules
  @modules ||= default_modules
end

.modules=(mods) ⇒ Object



40
41
42
# File 'lib/metaractor.rb', line 40

def self.modules=(mods)
  @modules = mods
end

.prepend_module(mod) ⇒ Object



58
59
60
# File 'lib/metaractor.rb', line 58

def self.prepend_module(mod)
  modules << {module: mod, method: :prepend}
end

.register_type(type, callable) ⇒ Object



86
87
88
# File 'lib/metaractor.rb', line 86

def self.register_type(type, callable)
  types[type] = callable
end

.typesObject



82
83
84
# File 'lib/metaractor.rb', line 82

def self.types
  @types ||= {}
end