Module: Eco::API::UseCases::GraphQL::Helpers::Pages::Copying

Includes:
Shortcuts, Language::AuxiliarLogger
Included in:
Samples::Pages::Register::MigrationCase
Defined in:
lib/eco/api/usecases/graphql/helpers/pages/copying.rb

Overview

Native GraphQL re-expression of OozeSamples::HelpersMigration::Copying.

Provides the "pair source fields to destination fields and copy their content across" flow used by the native migration case. Pairing is delegated to TypedFieldsPairing; the per-field content copy (copy_field_content) dispatches on the GraphQL DataField TYPE STRING (PlainText/Select/Date/...), mirroring how OozeHandlers#merge_values ports the v2 type-class dispatch.

Only the generic-typed-pairing flow is ported (the v2 regex/JSON hooked-field mapping — copy_hooked_fields / with_src_dst_field_pair — is a later increment and is intentionally omitted here).

Instance Attribute Summary

Attributes included from Language::AuxiliarLogger

#logger

Instance Method Summary collapse

Methods included from Shortcuts

#bracked_regex, #clean_question, #is_number?, #non_letters_regex, #normalize_string, #object_reference, #same_string?, #simplify_string, #titleize, #to_i

Methods included from Language::AuxiliarLogger

#log

Instance Method Details

#copy_field_content(src, dst) ⇒ Object

Copy the content of src into dst, dispatching on the GraphQL DataField TYPE STRING. src and dst are guaranteed to be the same type by the pairing. Types with no meaningful/copyable content (or whose native setter is not yet supported) are left untouched.

Parameters:

  • src (#type)

    the source data field.

  • dst (#type)

    the destination data field.

Returns:

  • (Object)

    result of the per-type copy (or a "won't copy" marker).



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/eco/api/usecases/graphql/helpers/pages/copying.rb', line 55

def copy_field_content(src, dst)
  case src.type.to_s
  when 'PlainText', 'Number', 'Date', 'Gauge'
    dst.value = src.value
  when 'RichText'
    dst.content = src.content
  when 'Select'
    dst.select_option(*src.selected_options.map { |opt| opt['id'] })
  when 'CrossReference'
    dst.page_ids = src.page_ids
  else
    "won't copy"
  end
end

#copy_generic_paired_fields(src, dst, src_excluded: [], dst_excluded: [], exclude_ximport: false) {|src_fld, dst_fld, pairing| ... } ⇒ TypedFieldsPairing

Pair the same-type/same-label fields of src and dst, and copy the content of each pair from source to destination.

Parameters:

  • src (Object)

    the source page model.

  • dst (Object)

    the destination (draft) page model.

  • src_excluded (Array) (defaults to: [])

    source fields to exclude from pairing.

  • dst_excluded (Array) (defaults to: [])

    destination fields to exclude from pairing.

  • exclude_ximport (Boolean) (defaults to: false)

    skip ximport-marked fields.

Yields:

  • (src_fld, dst_fld, pairing)

    optional post-copy callback per pair.

Returns:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/eco/api/usecases/graphql/helpers/pages/copying.rb', line 32

def copy_generic_paired_fields(src, dst, src_excluded: [], dst_excluded: [], exclude_ximport: false)
  TypedFieldsPairing.new(
    src,
    dst,
    src_excluded:    src_excluded,
    dst_excluded:    dst_excluded,
    exclude_ximport: exclude_ximport
  ).tap do |pairing|
    pairing.each_pair do |src_fld, dst_fld|
      copy_field_content(src_fld, dst_fld)
      yield(src_fld, dst_fld, pairing) if block_given?
    end
  end
end

#sessionObject



18
19
20
# File 'lib/eco/api/usecases/graphql/helpers/pages/copying.rb', line 18

def session
  defined?(super) ? super : @session
end