Sha256: b249670ffd89a74e5acfeeee0cb1bb89caab3d7bfe330bb8d373b7411934d505

Contents?: true

Size: 1.5 KB

Versions: 13

Compression:

Stored size: 1.5 KB

Contents

module Avro
  module Builder
    module Types

      # This concern provides error handling for attributes related to naming
      # that are handled differently at the top-level vs inline.
      module NamedErrorHandling

        # Errors for attributes specified via block

        def type_name(_value)
          name_attribute_error!
        end

        def type_namespace(_value)
          namespace_attribute_error!
        end

        private

        # Errors for misnamed options

        def name=(_value)
          type_name_instead_of_name_error!
        end

        def namespace=(_value)
          type_namespace_instead_of_namespace_error!
        end

        # Methods to raise errors

        def specify_as_type_option_error!(name)
          raise AttributeError
            .new("'type_#{name}' must be specified as an option, not via a block")
        end

        def name_attribute_error!
          specify_as_type_option_error!(:name)
        end

        def namespace_attribute_error!
          specify_as_type_option_error!(:namespace)
        end

        def type_option_instead_of_option_error!(name)
          raise AttributeError
            .new("'type_#{name}' must be specified as an option instead of '#{name}'")
        end

        def type_name_instead_of_name_error!
          type_option_instead_of_option_error!(:name)
        end

        def type_namespace_instead_of_namespace_error!
          type_option_instead_of_option_error!(:namespace)
        end

      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
avro-builder-0.16.1 lib/avro/builder/types/named_error_handling.rb
avro-builder-0.16.0 lib/avro/builder/types/named_error_handling.rb
avro-builder-0.15.0 lib/avro/builder/types/named_error_handling.rb
avro-builder-0.15.0.rc0 lib/avro/builder/types/named_error_handling.rb
avro-builder-0.14.1 lib/avro/builder/types/named_error_handling.rb
avro-builder-0.14.0 lib/avro/builder/types/named_error_handling.rb
avro-builder-0.13.0 lib/avro/builder/types/named_error_handling.rb
avro-builder-0.12.0 lib/avro/builder/types/named_error_handling.rb
avro-builder-0.11.0 lib/avro/builder/types/named_error_handling.rb
avro-builder-0.10.0 lib/avro/builder/types/named_error_handling.rb
avro-builder-0.9.0 lib/avro/builder/types/named_error_handling.rb
avro-builder-0.8.0 lib/avro/builder/types/named_error_handling.rb
avro-builder-0.7.0 lib/avro/builder/types/named_error_handling.rb