Class: ConvenientService::Core::Entities::Config::Commands::BuildEntityFromConfigOption

Inherits:
Support::Command
  • Object
show all
Defined in:
lib/convenient_service/core/entities/config/commands/build_entity_from_config_option.rb

Overview

Since:

  • 1.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(base_entity:, option:, detail_keys:) ⇒ void

Parameters:

Since:

  • 1.0.0



38
39
40
41
42
# File 'lib/convenient_service/core/entities/config/commands/build_entity_from_config_option.rb', line 38

def initialize(base_entity:, option:, detail_keys:)
  @base_entity = base_entity
  @option = option
  @detail_keys = detail_keys
end

Instance Attribute Details

#base_entity ⇒ Object (readonly)

Since:

  • 1.0.0



18
19
20
# File 'lib/convenient_service/core/entities/config/commands/build_entity_from_config_option.rb', line 18

def base_entity
  @base_entity
end

#config ⇒ ConvenientService::Config::Entities::Option (readonly)



24
# File 'lib/convenient_service/core/entities/config/commands/build_entity_from_config_option.rb', line 24

attr_reader :option

#detail_keys ⇒ Object (readonly)

Since:

  • 1.0.0



30
31
32
# File 'lib/convenient_service/core/entities/config/commands/build_entity_from_config_option.rb', line 30

def detail_keys
  @detail_keys
end

#option ⇒ Object (readonly)

Since:

  • 1.0.0



24
25
26
# File 'lib/convenient_service/core/entities/config/commands/build_entity_from_config_option.rb', line 24

def option
  @option
end

Instance Method Details

#call ⇒ Object

Returns Can be any type.

Returns:

  • (Object) —

    Can be any type.

Since:

  • 1.0.0



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/convenient_service/core/entities/config/commands/build_entity_from_config_option.rb', line 47

def call
  return base_entity unless option
  return base_entity if option.data.empty?
  return base_entity if detail_keys.empty?

  data_values = option.data.slice(*detail_keys)

  return base_entity if data_values.empty?

  base_entity.with(**data_values)
end