Sha256: 49114265958cab0bff491dc53d75c9329b02d7b274752ce7481337bb987684f9

Contents?: true

Size: 979 Bytes

Versions: 27

Compression:

Stored size: 979 Bytes

Contents

# Copyright (c) 2011 - 2013, SoundCloud Ltd., Rany Keddo, Tobias Bielohlawek, Tobias
# Schmidt

module Lhm
  #  Determine and format columns common to origin and destination.
  class Intersection
    def initialize(origin, destination, renames = {})
      @origin = origin
      @destination = destination
      @renames = renames
    end

    def origin
      (common + @renames.keys).extend(Joiners)
    end

    def destination
      (common + @renames.values).extend(Joiners)
    end

    private

    def common
      (@origin.columns.keys & @destination.columns.keys).sort
    end

    module Joiners
      def escaped
        map { |name| tick(name)  }
      end

      def joined
        escaped.join(', ')
      end

      def typed(type)
        map { |name| qualified(name, type)  }.join(', ')
      end

      private

      def qualified(name, type)
        "`#{ type }`.`#{ name }`"
      end

      def tick(name)
        "`#{ name }`"
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 2 rubygems

Version Path
lhm-shopify-4.4.2 lib/lhm/intersection.rb
lhm-shopify-4.4.1 lib/lhm/intersection.rb
lhm-shopify-4.4.0 lib/lhm/intersection.rb
lhm-shopify-4.3.0 lib/lhm/intersection.rb
lhm-shopify-4.2.3 lib/lhm/intersection.rb
lhm-shopify-4.2.2 lib/lhm/intersection.rb
lhm-shopify-4.2.1 lib/lhm/intersection.rb
lhm-shopify-4.2.0 lib/lhm/intersection.rb
lhm-shopify-4.1.1 lib/lhm/intersection.rb
lhm-shopify-4.1.0 lib/lhm/intersection.rb
lhm-shopify-4.0.0 lib/lhm/intersection.rb
lhm-teak-3.6.4 lib/lhm/intersection.rb
lhm-teak-3.6.3 lib/lhm/intersection.rb
lhm-teak-3.6.2 lib/lhm/intersection.rb
lhm-teak-3.6.1 lib/lhm/intersection.rb
lhm-teak-3.6.0 lib/lhm/intersection.rb
lhm-shopify-3.5.5 lib/lhm/intersection.rb
lhm-shopify-3.5.4 lib/lhm/intersection.rb
lhm-shopify-3.5.3 lib/lhm/intersection.rb
lhm-shopify-3.5.2 lib/lhm/intersection.rb