Sha256: 2636cbdca711c84df8101169cb7214ecf1a3d40d82a9d1af3fe1f69d3cf8c9c2

Contents?: true

Size: 1.55 KB

Versions: 5

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

require 'ostruct'

module GlobalRegistry #:nodoc:
  module Bindings #:nodoc:
    module Options
      class ClassOptions
        delegate :id_column,
                 :mdm_id_column,
                 :mdm_timeout,
                 :type,
                 :push_on,
                 :parent_association,
                 :related_association,
                 :parent_relationship_name,
                 :related_relationship_name,
                 :exclude_fields,
                 :extra_fields, to: :@options

        def initialize(model_class)
          @model_class = model_class
          @options = OpenStruct.new model_class._global_registry_bindings_options_hash
        end

        def parent_class
          return if parent_association.blank?
          @model_class.reflect_on_all_associations
                      .detect { |a| a.name == parent_association.to_sym }
              &.klass
        end

        def related_class
          return if related_association.blank?
          @model_class.reflect_on_all_associations
                      .detect { |a| a.name == related_association.to_sym }
            &.klass
        end

        def parent_is_self?
          parent_association.present? && parent_type == type
        end

        def parent_type
          parent_class&.global_registry&.type
        end

        def related_type
          related_class&.global_registry&.type
        end

        def mdm_worker_class_name
          "Pull#{@model_class.name.tr(':', '')}MdmIdWorker"
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
global-registry-bindings-0.0.5 lib/global_registry_bindings/options/class_options.rb
global-registry-bindings-0.0.4 lib/global_registry_bindings/options/class_options.rb
global-registry-bindings-0.0.3 lib/global_registry_bindings/options/class_options.rb
global-registry-bindings-0.0.2 lib/global_registry_bindings/options/class_options.rb
global-registry-bindings-0.0.1 lib/global_registry_bindings/options/class_options.rb