Class: PropsBuilder

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/activerecord-ejection_seat/props_builder.rb

Overview

Creates initialization payload for targeted T::Struct

Instance Method Summary collapse

Constructor Details

#initialize(model:, target_struct:) ⇒ PropsBuilder

Returns a new instance of PropsBuilder.



14
15
16
17
# File 'lib/activerecord-ejection_seat/props_builder.rb', line 14

def initialize(model:, target_struct:)
  @model = model
  @target_struct = target_struct
end

Instance Method Details

#buildObject



20
21
22
23
24
25
26
# File 'lib/activerecord-ejection_seat/props_builder.rb', line 20

def build
  target_struct.props.keys.each_with_object({}) do |prop_name, returned_props|
    attribute = model.respond_to?(prop_name) ? build_attribute(prop_name) : nil

    returned_props[prop_name] = attribute
  end
end