Class: Micro::Case

Inherits:
Object
  • Object
show all
Includes:
Attributes::Features::ActiveModelValidations
Defined in:
lib/micro/case.rb,
lib/micro/case/flow.rb,
lib/micro/case/safe.rb,
lib/micro/case/error.rb,
lib/micro/case/result.rb,
lib/micro/case/strict.rb,
lib/micro/case/version.rb,
lib/micro/case/safe/flow.rb,
lib/micro/case/flow/reducer.rb,
lib/micro/case/with_validation.rb

Direct Known Subclasses

Safe, Strict

Defined Under Namespace

Modules: Error, Flow Classes: Result, Safe, Strict

Constant Summary collapse

VERSION =
'2.3.1'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Case

Returns a new instance of Case.



94
95
96
# File 'lib/micro/case.rb', line 94

def initialize(input)
  __setup_use_case(input)
end

Class Method Details

.&(use_case) ⇒ Object



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

def self.&(use_case)
  Safe::Flow([self, use_case])
end

.>>(use_case) ⇒ Object



27
28
29
# File 'lib/micro/case.rb', line 27

def self.>>(use_case)
  Flow([self, use_case])
end

.__call!Object



45
46
47
48
49
50
51
52
53
# File 'lib/micro/case.rb', line 45

def self.__call!
  return const_get(:Flow_Step) if const_defined?(:Flow_Step)

  const_set(:Flow_Step, Class.new(self) do
    private def __call
      __call_use_case
    end
  end)
end

.__flow_getObject



63
64
65
# File 'lib/micro/case.rb', line 63

def self.__flow_get
  @__flow
end

.__flow_reducerObject



59
60
61
# File 'lib/micro/case.rb', line 59

def self.__flow_reducer
  Flow::Reducer
end

.__flow_set!Object



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

def self.__flow_set!
  __flow_set(__flow_use_cases_get) if !__flow_get && @__flow_use_cases
end

.__new__(result, arg) ⇒ Object



39
40
41
42
43
# File 'lib/micro/case.rb', line 39

def self.__new__(result, arg)
  instance = new(arg)
  instance.__set_result__(result)
  instance
end

.auto_validation_disabled?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/micro/case/with_validation.rb', line 9

def self.auto_validation_disabled?
  @disable_auto_validation
end

.call(options = {}) ⇒ Object



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

def self.call(options = {})
  new(options).call
end

.call!Object



55
56
57
# File 'lib/micro/case.rb', line 55

def self.call!
  self
end

.disable_auto_validationObject



13
14
15
# File 'lib/micro/case/with_validation.rb', line 13

def self.disable_auto_validation
  @disable_auto_validation = true
end

.Flow(args) ⇒ Object



23
24
25
# File 'lib/micro/case.rb', line 23

def self.Flow(args)
  Flow::Reducer.build(Array(args))
end

.flow(*args) ⇒ Object



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

def self.flow(*args)
  __flow_use_cases_set(args)
end

.to_procObject



19
20
21
# File 'lib/micro/case.rb', line 19

def self.to_proc
  Proc.new { |arg| call(arg) }
end

.use_casesObject



79
# File 'lib/micro/case.rb', line 79

def self.use_cases; __flow_get.use_cases; end

Instance Method Details

#__set_result__(result) ⇒ Object



106
107
108
109
110
111
# File 'lib/micro/case.rb', line 106

def __set_result__(result)
  raise Error::InvalidResultInstance unless result.is_a?(Result)
  raise Error::ResultIsAlreadyDefined if @__result

  @__result = result
end

#callObject



102
103
104
# File 'lib/micro/case.rb', line 102

def call
  __call
end

#call!Object

Raises:

  • (NotImplementedError)


98
99
100
# File 'lib/micro/case.rb', line 98

def call!
  raise NotImplementedError
end