Module: Lite::Service::Command

Defined in:
lib/lite/service/command.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



24
25
26
# File 'lib/lite/service/command.rb', line 24

def result
  @result
end

Class Method Details

.prepended(base) ⇒ Object



26
27
28
# File 'lib/lite/service/command.rb', line 26

def self.prepended(base)
  base.extend(ClassMethods)
end

Instance Method Details

#cacheObject



38
39
40
# File 'lib/lite/service/command.rb', line 38

def cache
  @cache ||= Lite::Memoize::Instance.new
end

#callObject



30
31
32
33
34
35
36
# File 'lib/lite/service/command.rb', line 30

def call
  raise Lite::Service::NotImplementedError unless defined?(super)
  return @result if called?

  @called = true
  @result = super
end

#called?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/lite/service/command.rb', line 42

def called?
  @called ||= false
end

#errored?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/lite/service/command.rb', line 50

def errored?
  !errors.empty?
end

#errorsObject



46
47
48
# File 'lib/lite/service/command.rb', line 46

def errors
  @errors ||= Lite::Errors::Messages.new
end

#fail!Object



54
55
56
# File 'lib/lite/service/command.rb', line 54

def fail!
  raise Lite::Service::ValidationError
end

#failure?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/lite/service/command.rb', line 58

def failure?
  called? && errored?
end

#recall!Object



62
63
64
65
66
# File 'lib/lite/service/command.rb', line 62

def recall!
  @called = false
  [cache, errors].each(&:clear)
  call
end

#result!Object



68
69
70
# File 'lib/lite/service/command.rb', line 68

def result!
  result if valid?
end

#success?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/lite/service/command.rb', line 72

def success?
  called? && !errored?
end

#validate!Object Also known as: valid?



76
77
78
79
80
# File 'lib/lite/service/command.rb', line 76

def validate!
  return true if success?

  fail!
end