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/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, Parameters, RunWithContext, Spec Classes: Error, Errors, InvalidError

Constant Summary collapse

VERSION =
"3.3.0"

Class Method Summary collapse

Class Method Details

.clear_types!Object



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

def self.clear_types!
  @types = {}
end

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

Yields:

  • (_self)

Yield Parameters:

  • _self (Metaractor)

    the object that the method was called on



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

def self.configure
  yield self
end

.default_hash_formatterObject



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

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

.default_modulesObject



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

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



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

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

  @hash_formatter.call(hash)
end

.hash_formatterObject



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

def self.hash_formatter
  @hash_formatter
end

.hash_formatter=(callable) ⇒ Object



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

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

.include_module(mod) ⇒ Object



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

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

.included(base) ⇒ Object



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

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



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

def self.modules
  @modules ||= default_modules
end

.modules=(mods) ⇒ Object



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

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

.prepend_module(mod) ⇒ Object



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

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

.register_type(type, callable) ⇒ Object



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

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

.typesObject



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

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