Sha256: 233522787bb8ebdd24858a6ed62162c8b55d1e1f3fff7098e390c5553c082e18

Contents?: true

Size: 1.15 KB

Versions: 28

Compression:

Stored size: 1.15 KB

Contents

module Ecoportal
  module API
    class Internal
      class Person

        def new?(doc = :initial)
          ref_doc = (doc == :original) ? original_doc : initial_doc
          !ref_doc["details"] && !ref_doc["account"]
        end

        # @return [Boolean] if the account has been added, compared to `doc`
        def account_added?(doc = :initial)
          ref_doc = (doc == :original) ? original_doc : initial_doc
          account && !ref_doc["account"]
        end

        # It replaces `doc` by `new_doc`
        # @return [Hash] `doc` before change
        def replace_doc!(new_doc)
          raise UnlinkedModel.new(from: "#{self.class}#replace_doc", key: _key) unless linked?
          @doc.tap do
            @doc = new_doc
          end
        end

        # It replaces `original_doc` by `new_doc`
        # @return [Hash] `original_doc` before change
        def replace_original_doc!(new_doc)
          raise UnlinkedModel.new(from: "#{self.class}#replace_original_doc", key: _key) unless linked?
          @original_doc.tap do
            @original_doc = new_doc
          end
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
eco-helpers-2.2.5 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.2.4 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.2.3 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.2.2 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.2.1 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.1.12 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.1.11 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.1.10 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.1.9 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.1.8 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.1.7 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.1.6 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.1.5 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.1.4 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.1.3 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.1.2 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.1.1 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.0.68 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.0.67 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb
eco-helpers-2.0.66 lib/eco/api/common/version_patches/ecoportal_api/internal_person.rb