Module: SimpleCommand

Defined in:
lib/simple_command.rb,
lib/simple_command/utils.rb,
lib/simple_command/errors.rb,
lib/simple_command/version.rb

Defined Under Namespace

Modules: ClassMethods, Utils Classes: Errors, NotImplementedError

Constant Summary collapse

VERSION =
'1.0.1'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



6
7
8
# File 'lib/simple_command.rb', line 6

def result
  @result
end

Class Method Details

.prepended(base) ⇒ Object



14
15
16
# File 'lib/simple_command.rb', line 14

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

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
# File 'lib/simple_command.rb', line 18

def call
  fail NotImplementedError unless defined?(super)

  @called = true
  @result = super

  self
end

#errorsObject



36
37
38
39
40
# File 'lib/simple_command.rb', line 36

def errors
  return super if defined?(super)

  @errors ||= Errors.new
end

#failure?Boolean

Returns:

  • (Boolean)


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

def failure?
  called? && errors.any?
end

#success?Boolean Also known as: successful?

Returns:

  • (Boolean)


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

def success?
  called? && !failure?
end