Sha256: 585fa1a7a2cc09ff360349268b24b0fe1b5b2081aae9de57867613a7d5cda464

Contents?: true

Size: 1.72 KB

Versions: 76

Compression:

Stored size: 1.72 KB

Contents

# -*- ruby -*-
# frozen_string_literal: true

module PG

	class Coder

		module BinaryFormatting
			Params = { format: 1 }
			def initialize( params={} )
				super(Params.merge(params))
			end
		end


		# Create a new coder object based on the attribute Hash.
		def initialize(params={})
			params.each do |key, val|
				send("#{key}=", val)
			end
		end

		def dup
			self.class.new(to_h)
		end

		# Returns coder attributes as Hash.
		def to_h
			{
				oid: oid,
				format: format,
				flags: flags,
				name: name,
			}
		end

		def ==(v)
			self.class == v.class && to_h == v.to_h
		end

		def marshal_dump
			Marshal.dump(to_h)
		end

		def marshal_load(str)
			initialize Marshal.load(str)
		end

		def inspect
			str = self.to_s
			oid_str = " oid=#{oid}" unless oid==0
			format_str = " format=#{format}" unless format==0
			name_str = " #{name.inspect}" if name
			str[-1,0] = "#{name_str} #{oid_str}#{format_str}"
			str
		end

		def inspect_short
			str = case format
				when 0 then "T"
				when 1 then "B"
				else format.to_s
			end
			str += "E" if respond_to?(:encode)
			str += "D" if respond_to?(:decode)

			"#{name || self.class.name}:#{str}"
		end
	end

	class CompositeCoder < Coder
		def to_h
			super.merge!({
				elements_type: elements_type,
				needs_quotation: needs_quotation?,
				delimiter: delimiter,
			})
		end

		def inspect
			str = super
			str[-1,0] = " elements_type=#{elements_type.inspect} #{needs_quotation? ? 'needs' : 'no'} quotation"
			str
		end
	end

	class CopyCoder < Coder
		def to_h
			super.merge!({
				type_map: type_map,
				delimiter: delimiter,
				null_string: null_string,
			})
		end
	end

	class RecordCoder < Coder
		def to_h
			super.merge!({
				type_map: type_map,
			})
		end
	end
end # module PG

Version data entries

76 entries across 76 versions & 4 rubygems

Version Path
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/coder.rb
cipherstash-pg-1.0.0.beta.1-x86_64-darwin-21 ./lib/pg/coder.rb
cipherstash-pg-1.0.0.beta.1-arm64-darwin-21 ./lib/pg/coder.rb
cipherstash-pg-1.0.0.beta.1-x86_64-linux ./lib/pg/coder.rb
cipherstash-pg-1.0.0.beta.1-x86_64-darwin-22 ./lib/pg/coder.rb
cipherstash-pg-1.0.0.beta.1-arm64-darwin-22 ./lib/pg/coder.rb
cipherstash-pg-1.0.0.beta.1-aarch64-linux ./lib/pg/coder.rb
pg-1.4.6-x86-mingw32 lib/pg/coder.rb
pg-1.4.6-x64-mingw32 lib/pg/coder.rb
pg-1.4.6-x64-mingw-ucrt lib/pg/coder.rb
pg-1.4.6 lib/pg/coder.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/coder.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/coder.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/pg-1.4.5/lib/pg/coder.rb
pg-1.4.5-x86-mingw32 lib/pg/coder.rb
pg-1.4.5-x64-mingw-ucrt lib/pg/coder.rb
pg-1.4.5-x64-mingw32 lib/pg/coder.rb
pg-1.4.5 lib/pg/coder.rb
pg-1.4.4-x86-mingw32 lib/pg/coder.rb
pg-1.4.4-x64-mingw32 lib/pg/coder.rb