Sha256: f3762d0eaae1eab6c6fe686f673edd0f12414eb09bd9432ddc064941cbde32a8

Contents?: true

Size: 1.05 KB

Versions: 26

Compression:

Stored size: 1.05 KB

Contents

module Foobara
  module BuiltinTypes
    module Attributes
      module SupportedTransformers
        class Defaults < Value::Transformer
          class << self
            def requires_parent_declaration_data?
              true
            end
          end

          def transform(attributes_hash)
            to_apply = {}

            defaults.each_pair do |attribute_name, default|
              if attributes_hash.key?(attribute_name)
                value = attributes_hash[attribute_name]

                if value.nil?
                  allow_nil = parent_declaration_data[:element_type_declarations][attribute_name][:allow_nil]

                  unless allow_nil
                    to_apply[attribute_name] = default
                  end
                end
              else
                to_apply[attribute_name] = default
              end
            end

            if to_apply.empty?
              attributes_hash
            else
              attributes_hash.merge(to_apply)
            end
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.25 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.24 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.23 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.22 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.21 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.20 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.19 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.18 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.17 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.16 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.15 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.14 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.13 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.12 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.11 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.10 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.9 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.8 projects/builtin_types/src/attributes/supported_transformers/defaults.rb
foobara-0.0.7 projects/builtin_types/src/attributes/supported_transformers/defaults.rb