Class: Solid::Process

Inherits:
Object
  • Object
show all
Extended by:
ClassMethods
Includes:
ActiveSupport::Rescuable, Callbacks
Defined in:
lib/solid/process/caller.rb,
lib/solid/process.rb,
lib/solid/process/error.rb,
lib/solid/process/config.rb,
lib/solid/process/version.rb,
lib/solid/process/callbacks.rb,
lib/solid/process/event_logs.rb,
lib/solid/process/active_record.rb,
lib/solid/process/class_methods.rb

Overview

rubocop:disable Lint/RescueException

Defined Under Namespace

Modules: Callbacks, Caller, ClassMethods, EventLogs Classes: BacktraceCleaner, Config

Constant Summary collapse

Error =
::Class.new(::StandardError)
VERSION =
"0.4.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Callbacks

included

Constructor Details

#initialize(arg = nil) ⇒ Process

Returns a new instance of Process.



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

def initialize(arg = nil)
  self.dependencies = arg
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



93
94
95
# File 'lib/solid/process.rb', line 93

def method_missing(name, *args, &block)
  name.end_with?("?") ? output&.is?(name.to_s.chomp("?")) : super
end

Instance Attribute Details

#dependenciesObject Also known as: deps

Returns the value of attribute dependencies.



51
52
53
# File 'lib/solid/process.rb', line 51

def dependencies
  @dependencies
end

#inputObject

Returns the value of attribute input.



51
52
53
# File 'lib/solid/process.rb', line 51

def input
  @input
end

#outputObject Also known as: result

Returns the value of attribute output.



51
52
53
# File 'lib/solid/process.rb', line 51

def output
  @output
end

Class Method Details

.call(arg = nil) ⇒ Object



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

def self.call(arg = nil)
  new.call(arg)
end

.configObject



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

def self.config
  Config.instance
end

.configuration(freeze: true) {|config| ... } ⇒ Object

Yields:



43
44
45
46
47
# File 'lib/solid/process.rb', line 43

def self.configuration(freeze: true, &block)
  yield config

  config.tap { _1.freeze if freeze }
end

.inherited(subclass) ⇒ Object



29
30
31
32
33
# File 'lib/solid/process.rb', line 29

def self.inherited(subclass)
  super

  subclass.prepend(Caller)
end

Instance Method Details

#call(_arg = nil) ⇒ Object

Raises:



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

def call(_arg = nil)
  raise Error, "#{self.class}#call must be implemented."
end

#dependencies?Boolean Also known as: deps?

Returns:

  • (Boolean)


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

def dependencies?
  !dependencies.nil?
end

#failure?(type = nil) ⇒ Boolean

Returns:

  • (Boolean)


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

def failure?(type = nil)
  !!output&.failure?(type)
end

#input?Boolean

Returns:

  • (Boolean)


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

def input?
  !input.nil?
end

#inspectObject



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

def inspect
  "#<#{self.class.name} dependencies=#{dependencies.inspect} input=#{input.inspect} output=#{output.inspect}>"
end

#new(dependencies = {}) ⇒ Object



65
66
67
# File 'lib/solid/process.rb', line 65

def new(dependencies = {})
  with(dependencies)
end

#output?(type = nil) ⇒ Boolean Also known as: result?

Returns:

  • (Boolean)


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

def output?(type = nil)
  type.nil? ? !output.nil? : !!output&.is?(type)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/solid/process.rb', line 97

def respond_to_missing?(name, include_private = false)
  name.end_with?("?") || super
end

#success?(type = nil) ⇒ Boolean

Returns:

  • (Boolean)


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

def success?(type = nil)
  !!output&.success?(type)
end

#with(dependencies) ⇒ Object



61
62
63
# File 'lib/solid/process.rb', line 61

def with(dependencies)
  self.class.new(dependencies.with_indifferent_access.with_defaults(deps&.attributes))
end