Sha256: 0bed47f5626ad46b3e2ad32f45bfa08f14118e71140bec861857faa8398d0064

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

module Workarea
  decorate HashUpdate, with: :design_toscano do
    decorated do
      # Place code to decorate here that would normally go on the class
      # level, e.g.:
      #
      #     field :name, type: String
    end

    class_methods do
      # Place methods to define on the class level here. These methods
      # will be available by calling HashUpdate.your_method. Do
      # not prefix these methods with `self.`
    end

    def result_grouped
      apply_to_grouped(@original.deep_dup)
    end

    private

    def apply_to_grouped(hash)
      @adds.each do |tuple|
        key, value = *tuple
        hash[key] = value
      end

      @updates.each do |tuple|
        key, value = *tuple
        hash[key] = value
      end

      @removes.each do |key|
        hash.delete(key)
      end

      hash.delete_if { |k, v| k.blank? || v.blank? }
    end
    # Instance methods can go right in the main definition of the
    # decorator, as it is a module that gets prepended into the class of
    # your choice.
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
workarea-product_additional_details-2.0.0 app/services/workarea/hash_update.decorator
workarea-product_additional_details-0.0.3 app/services/workarea/hash_update.decorator