Sha256: 1ed9a60aca3b89c95888d29377db4747676ef35bcd72046c34c1b75a3fd1c3da

Contents?: true

Size: 1.48 KB

Versions: 11

Compression:

Stored size: 1.48 KB

Contents

module Foobara
  module BuiltinTypes
    module Model
      # TODO: Create Mutations/SupportedMutations concept
      class Transformers
        class Mutable < TypeDeclarations::Transformer
          class << self
            def requires_parent_declaration_data?
              true
            end
          end

          def transform(record)
            if parent_declaration_data.key?(:mutable)
              # hmmmm.... can we really just arbitrarily clobber this?
              # wouldn't that be surprising to calling code that passes in a record/model?
              # One use-case of this seems to be to reduce the amount of possible errors a command reports
              # by declaring that only some subset or none of the attributes are mutable.
              # However, we shouldn't react to this by clobbering the mutable state of the record because it might not
              # be a fresh record fetched from a primary key it might be an already loaded record/model from some other
              # context and that context might be surprised to learn that we've clobbered its mutability status.
              # Solutions?
              # 1. In the case of models, we could duplicate the model if the mutable value is different.
              # 2. But what about entities? We almost need some sort of proxy entity that tightens the mutability?
              record.mutable = parent_declaration_data[:mutable]
            end

            record
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/model/src/extensions/builtin_types/model/transformers/mutable.rb
foobara-0.0.25 projects/model/src/extensions/builtin_types/model/transformers/mutable.rb
foobara-0.0.24 projects/model/src/extensions/builtin_types/model/transformers/mutable.rb
foobara-0.0.23 projects/model/src/extensions/builtin_types/model/transformers/mutable.rb
foobara-0.0.22 projects/model/src/extensions/builtin_types/model/transformers/mutable.rb
foobara-0.0.21 projects/model/src/extensions/builtin_types/model/transformers/mutable.rb
foobara-0.0.20 projects/model/src/extensions/builtin_types/model/transformers/mutable.rb
foobara-0.0.19 projects/model/src/extensions/builtin_types/model/transformers/mutable.rb
foobara-0.0.18 projects/model/src/extensions/builtin_types/model/transformers/mutable.rb
foobara-0.0.17 projects/model/src/extensions/builtin_types/model/transformers/mutable.rb
foobara-0.0.16 projects/model/src/extensions/builtin_types/model/transformers/mutable.rb