Class: CommandTower::UserAttributes::Mutate::Outcome

Inherits:
Object
  • Object
show all
Defined in:
app/services/command_tower/user_attributes/mutate.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(success:, user:, attribute: nil, msg: nil, invalid_argument_hash: {}) ⇒ Outcome

Returns a new instance of Outcome.



29
30
31
32
33
34
35
# File 'app/services/command_tower/user_attributes/mutate.rb', line 29

def initialize(success:, user:, attribute: nil, msg: nil, invalid_argument_hash: {})
  @success = success
  @user = user
  @attribute = attribute
  @msg = msg
  @invalid_argument_hash = invalid_argument_hash
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



16
17
18
# File 'app/services/command_tower/user_attributes/mutate.rb', line 16

def attribute
  @attribute
end

#invalid_argument_hashObject (readonly)

Returns the value of attribute invalid_argument_hash.



16
17
18
# File 'app/services/command_tower/user_attributes/mutate.rb', line 16

def invalid_argument_hash
  @invalid_argument_hash
end

#msgObject (readonly)

Returns the value of attribute msg.



16
17
18
# File 'app/services/command_tower/user_attributes/mutate.rb', line 16

def msg
  @msg
end

#userObject (readonly)

Returns the value of attribute user.



16
17
18
# File 'app/services/command_tower/user_attributes/mutate.rb', line 16

def user
  @user
end

Class Method Details

.invalid(user:, errors:) ⇒ Object



22
23
24
25
26
27
# File 'app/services/command_tower/user_attributes/mutate.rb', line 22

def self.invalid(user:, errors:)
  invalid_argument_hash = errors.transform_values { { msg: _1 } }
  msg = "Invalid arguments: #{errors.map { |key, message| "#{key}: #{message}" }.join(", ")}"

  new(success: false, user:, msg:, invalid_argument_hash:)
end

.success(user:, attribute:) ⇒ Object



18
19
20
# File 'app/services/command_tower/user_attributes/mutate.rb', line 18

def self.success(user:, attribute:)
  new(success: true, user:, attribute:)
end

Instance Method Details

#failure?Boolean

Returns:

  • (Boolean)


39
# File 'app/services/command_tower/user_attributes/mutate.rb', line 39

def failure? = !@success

#invalid_argument_keysObject



43
# File 'app/services/command_tower/user_attributes/mutate.rb', line 43

def invalid_argument_keys = invalid_argument_hash.keys

#invalid_argumentsObject



41
# File 'app/services/command_tower/user_attributes/mutate.rb', line 41

def invalid_arguments = failure?

#success?Boolean

Returns:

  • (Boolean)


37
# File 'app/services/command_tower/user_attributes/mutate.rb', line 37

def success? = @success