Sha256: 7d5cd1df2d16922c44ce4102744d4a09a40899dbeba270777fcba6d24736213a

Contents?: true

Size: 1.49 KB

Versions: 7

Compression:

Stored size: 1.49 KB

Contents

module Foobara
  class Entity < Model
    module Concerns
      module Reflection
        include Concern

        module ClassMethods
          def depends_on
            associations.values.map(&:target_class).uniq
          end

          def deep_depends_on
            types = deep_associations.sort_by do |path, _type|
              [DataPath.new(path).path.size, path]
            end.map(&:last)

            types.map(&:target_class).uniq
          end

          def foobara_manifest(to_include: Set.new)
            associations = self.associations.map do |(path, type)|
              entity_class = type.target_class
              entity_name = entity_class.full_entity_name

              [path, entity_name]
            end.sort.to_h

            deep_associations = self.deep_associations.map do |(path, type)|
              entity_class = type.target_class
              entity_name = entity_class.full_entity_name

              [path, entity_name]
            end.sort.to_h

            super.merge(
              Util.remove_blank(
                depends_on: depends_on.map(&:full_entity_name),
                deep_depends_on: deep_depends_on.map(&:full_entity_name),
                associations:,
                deep_associations:,
                entity_name:,
                primary_key_attribute:,
                primary_key_type: attributes_type.declaration_data[:element_type_declarations][primary_key_attribute]
              )
            )
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
foobara-0.0.27 projects/entity/src/concerns/reflection.rb
foobara-0.0.26 projects/entity/src/concerns/reflection.rb
foobara-0.0.25 projects/entity/src/concerns/reflection.rb
foobara-0.0.24 projects/entity/src/concerns/reflection.rb
foobara-0.0.23 projects/entity/src/concerns/reflection.rb
foobara-0.0.22 projects/entity/src/concerns/reflection.rb
foobara-0.0.21 projects/entity/src/concerns/reflection.rb