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/utils.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_activemodel_validation.rb

Direct Known Subclasses

Safe, Strict

Defined Under Namespace

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

Constant Summary collapse

VERSION =
'2.4.0'.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input) ⇒ Case

Returns a new instance of Case.



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

def initialize(input)
  __setup_use_case(input)
end

Class Method Details

.&(use_case) ⇒ Object



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

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

.>>(use_case) ⇒ Object



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

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

.__call!Object



54
55
56
57
58
59
60
61
62
# File 'lib/micro/case.rb', line 54

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

.__call_and_set_transition__(result, arg) ⇒ Object



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

def self.__call_and_set_transition__(result, arg)
  if arg.respond_to?(:keys)
    result.__set_transitions_accessible_attributes__(arg.keys)
  end

  __new__(result, arg).call
end

.__flow_getObject



72
73
74
# File 'lib/micro/case.rb', line 72

def self.__flow_get
  return @__flow if defined?(@__flow)
end

.__flow_reducerObject



68
69
70
# File 'lib/micro/case.rb', line 68

def self.__flow_reducer
  Flow::Reducer
end

.__flow_set!Object



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

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

.__new__(result, arg) ⇒ Object



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

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_activemodel_validation.rb', line 9

def self.auto_validation_disabled?
  return @disable_auto_validation if defined?(@disable_auto_validation)
end

.call(options = {}) ⇒ Object



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

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

.call!Object



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

def self.call!
  self
end

.disable_auto_validationObject



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

def self.disable_auto_validation
  @disable_auto_validation = true
end

.Flow(args) ⇒ Object



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

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

.flow(*args) ⇒ Object



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

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

.to_procObject



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

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

.use_casesObject



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

def self.use_cases; __flow_get.use_cases; end

Instance Method Details

#__set_result__(result) ⇒ Object



119
120
121
122
123
124
# File 'lib/micro/case.rb', line 119

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

  @__result = result
end

#callObject



115
116
117
# File 'lib/micro/case.rb', line 115

def call
  __call
end

#call!Object

Raises:

  • (NotImplementedError)


111
112
113
# File 'lib/micro/case.rb', line 111

def call!
  raise NotImplementedError
end