Class: App::Command::Result

Inherits:
Struct
  • Object
show all
Defined in:
lib/has_helpers/app/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**attrs) ⇒ Result

Accept Hash values for attributes. Result.new(error: "Something bad happened") # => # Result.new(invalid_attr: nil) # => ArgumentError: Unknown struct member: :invalid_attr

Raises:

  • (::ArgumentError)


16
17
18
19
20
# File 'lib/has_helpers/app/command.rb', line 16

def initialize(**attrs)
  unknown_attrs = attrs.keys - self.class.members
  raise ::ArgumentError, "Unknown struct member#{ unknown_attrs.length == 1 ? "" : "s" }: #{ unknown_attrs.map(&:inspect).join(", ") }" unless unknown_attrs.empty?
  super(*attrs.values_at(*self.class.members))
end

Instance Attribute Details

#errorObject

Returns the value of attribute error

Returns:

  • (Object)

    the current value of error



10
11
12
# File 'lib/has_helpers/app/command.rb', line 10

def error
  @error
end

#exceptionObject

Returns the value of attribute exception

Returns:

  • (Object)

    the current value of exception



10
11
12
# File 'lib/has_helpers/app/command.rb', line 10

def exception
  @exception
end

#explicit_valueObject

Returns the value of attribute explicit_value

Returns:

  • (Object)

    the current value of explicit_value



10
11
12
# File 'lib/has_helpers/app/command.rb', line 10

def explicit_value
  @explicit_value
end

#explicit_value_is_setObject

Returns the value of attribute explicit_value_is_set.



11
12
13
# File 'lib/has_helpers/app/command.rb', line 11

def explicit_value_is_set
  @explicit_value_is_set
end

#failedObject

Returns the value of attribute failed.



11
12
13
# File 'lib/has_helpers/app/command.rb', line 11

def failed
  @failed
end

Instance Method Details

#fail(msg = nil) ⇒ Object



22
23
24
25
# File 'lib/has_helpers/app/command.rb', line 22

def fail(msg = nil)
  self.failed = true
  self.error ||= msg
end

#fail!(msg = nil) ⇒ Object

Raises:



27
28
29
30
# File 'lib/has_helpers/app/command.rb', line 27

def fail!(msg = nil)
  fail(msg)
  raise FailureError, error
end

#valueObject



37
38
39
# File 'lib/has_helpers/app/command.rb', line 37

def value
  explicit_value
end

#value=(v) ⇒ Object



32
33
34
35
# File 'lib/has_helpers/app/command.rb', line 32

def value=(v)
  self.explicit_value_is_set = true
  self.explicit_value = v
end