Sha256: a0167690b485ee2cf986eb1d6e5d8516d020275a46a9764ebdccbb49bb3b4838

Contents?: true

Size: 1.21 KB

Versions: 8

Compression:

Stored size: 1.21 KB

Contents

module Foobara
  module BuiltinTypes
    module DetachedEntity
      module Validators
        class AttributesDeclaration < Model::Validators::AttributesDeclaration
          # Why is this here in entity/ instead of in model/?
          def possible_errors
            return [] if parent_declaration_data == { type: expected_type_symbol }

            # TODO: we should also ask the class if it is mutable...
            mutable = parent_declaration_data.key?(:mutable) ? parent_declaration_data[:mutable] : false

            entity_class.possible_errors(mutable:)
          end

          def entity_class
            if parent_declaration_data.key?(:model_class)
              Object.const_get(parent_declaration_data[:model_class])
            elsif parent_declaration_data[:type] != expected_type_symbol
              model_type = type_for_declaration(parent_declaration_data[:type])
              model_type.target_class
            else
              # :nocov:
              raise "Missing :model_class in parent_declaration_data for #{parent_declaration_data}"
              # :nocov:
            end
          end

          def expected_type_symbol
            :detached_entity
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
foobara-0.0.38 projects/detached_entity/src/extensions/builtin_types/detached_entity/validators/attributes_declaration.rb
foobara-0.0.37 projects/detached_entity/src/extensions/builtin_types/detached_entity/validators/attributes_declaration.rb
foobara-0.0.36 projects/detached_entity/src/extensions/builtin_types/detached_entity/validators/attributes_declaration.rb
foobara-0.0.35 projects/detached_entity/src/extensions/builtin_types/detached_entity/validators/attributes_declaration.rb
foobara-0.0.34 projects/detached_entity/src/extensions/builtin_types/detached_entity/validators/attributes_declaration.rb
foobara-0.0.33 projects/detached_entity/src/extensions/builtin_types/detached_entity/validators/attributes_declaration.rb
foobara-0.0.32 projects/detached_entity/src/extensions/builtin_types/detached_entity/validators/attributes_declaration.rb
foobara-0.0.31 projects/detached_entity/src/extensions/builtin_types/detached_entity/validators/attributes_declaration.rb