Class: Zodra::TypeDeriver
- Inherits:
-
Object
- Object
- Zodra::TypeDeriver
- Defined in:
- lib/zodra/type_deriver.rb
Instance Method Summary collapse
- #apply(target_definition) ⇒ Object
-
#initialize(source_definition, pick: nil, omit: nil, partial: false) ⇒ TypeDeriver
constructor
A new instance of TypeDeriver.
Constructor Details
#initialize(source_definition, pick: nil, omit: nil, partial: false) ⇒ TypeDeriver
Returns a new instance of TypeDeriver.
5 6 7 8 9 10 11 12 13 |
# File 'lib/zodra/type_deriver.rb', line 5 def initialize(source_definition, pick: nil, omit: nil, partial: false) raise ArgumentError, 'Cannot use both :pick and :omit' if pick && omit raise ArgumentError, 'Source must be an object type' unless source_definition.object? @source = source_definition @pick = pick&.map(&:to_sym) @omit = omit&.map(&:to_sym) @partial = partial end |
Instance Method Details
#apply(target_definition) ⇒ Object
15 16 17 18 19 |
# File 'lib/zodra/type_deriver.rb', line 15 def apply(target_definition) selected_attributes.each do |name, attribute| copy_attribute(target_definition, name, attribute, optional: @partial && !attribute.optional?) end end |