Sha256: 4381fa43614f6249b4c77cbdf5bd1161b1d9ee26ea0c64bb67dad2c3974d057c

Contents?: true

Size: 849 Bytes

Versions: 11

Compression:

Stored size: 849 Bytes

Contents

module OpenApi
  module Helpers
    def fusion
      proc { |a, b| a.deep_merge!(b) { |common_key, va, vb| common_key == :required ? va + vb : vb } }
    end

    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

    # reducx.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)
      processed[who.to_sym] = @assign
      processed
    end

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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
zero-rails_openapi-1.7.0 lib/oas_objs/helpers.rb
zero-rails_openapi-1.6.1 lib/oas_objs/helpers.rb
zero-rails_openapi-1.6.0 lib/oas_objs/helpers.rb
zero-rails_openapi-1.5.9 lib/oas_objs/helpers.rb
zero-rails_openapi-1.5.8 lib/oas_objs/helpers.rb
zero-rails_openapi-1.5.7 lib/oas_objs/helpers.rb
zero-rails_openapi-1.5.6 lib/oas_objs/helpers.rb
zero-rails_openapi-1.5.5 lib/oas_objs/helpers.rb
zero-rails_openapi-1.5.4 lib/oas_objs/helpers.rb
zero-rails_openapi-1.5.3 lib/oas_objs/helpers.rb
zero-rails_openapi-1.5.2 lib/oas_objs/helpers.rb