Sha256: 1a04ac16da0b60d40c72fb557e0a6f52885adf6a9bfd7677d428582649e0e845

Contents?: true

Size: 923 Bytes

Versions: 1

Compression:

Stored size: 923 Bytes

Contents

module OpenApi
  module Helpers
    # TODO: comment-block doc
    def truly_present?(obj)
      obj == false || obj.present?
    end

    def value_present
      proc { |_, v| truly_present? v }
    end

    # assign.to
    def assign(value)
      @assign = value.is_a?(Symbol) ? send("_#{value}") : value
      self
    end

    # reduceee.then_merge! => for Hash
    def reducx(*values)
      @assign = values.compact.reduce({ }, :merge).keep_if &value_present
      self
    end

    def to_processed(who)
      return processed unless truly_present?(@assign)

      if who.is_a?(Symbol)
        send("#{who}=", @assign)
      else
        processed[who.to_sym] = @assign
      end

      processed
    end

    def to(who)
      self[who.to_sym] = @assign if truly_present?(@assign)
    end

    def then_merge! # to_processed
      processed.tap { |it| it.merge! @assign if truly_present?(@assign) }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
zero-rails_openapi-1.4.0 lib/oas_objs/helpers.rb