Sha256: ae7c93f74330d64b451535eda2c4e264d8d0767d4b68a53af1b0f5ebba6a35c1

Contents?: true

Size: 1.6 KB

Versions: 79

Compression:

Stored size: 1.6 KB

Contents

require("json")
require("ipaddr")
module CipherStashPG
  module TextEncoder
    class Date < SimpleEncoder
      def encode(value)
        value.respond_to?(:strftime) ? (value.strftime("%Y-%m-%d")) : (value)
      end
    end
    
    class TimestampWithoutTimeZone < SimpleEncoder
      def encode(value)
        if value.respond_to?(:strftime) then
          value.strftime("%Y-%m-%d %H:%M:%S.%N")
        else
          value
        end
      end
    end
    
    class TimestampUtc < SimpleEncoder
      def encode(value)
        if value.respond_to?(:utc) then
          value.utc.strftime("%Y-%m-%d %H:%M:%S.%N")
        else
          value
        end
      end
    end
    
    class TimestampWithTimeZone < SimpleEncoder
      def encode(value)
        if value.respond_to?(:strftime) then
          value.strftime("%Y-%m-%d %H:%M:%S.%N %:z")
        else
          value
        end
      end
    end
    
    class JSON < SimpleEncoder
      def encode(value)
        ::JSON.generate(value, :quirks_mode => true)
      end
    end
    
    class Inet < SimpleEncoder
      def encode(value)
        case value
        when IPAddr then
          default_prefix = (value.family == Socket::AF_INET) ? (32) : (128)
          s = value.to_s
          if value.respond_to?(:prefix) then
            prefix = value.prefix
          else
            range = value.to_range
            prefix = (default_prefix - Math.log(((range.end.to_i - range.begin.to_i) + 1), 2).to_i)
          end
          ((s << "/") << prefix.to_s) if (prefix != default_prefix)
          s
        else
          value
        end
      end
    end
  end
end

Version data entries

79 entries across 79 versions & 1 rubygems

Version Path
cipherstash-pg-1.0.0.beta.22-x86_64-linux ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.22-x86_64-darwin ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.22-arm64-darwin ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.22-aarch64-linux ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.21-x86_64-linux ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.21-aarch64-linux ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.21-arm64-darwin ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.21-x86_64-darwin ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.19-x86_64-linux ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.19-x86_64-darwin ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.19-arm64-darwin ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.19-aarch64-linux ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.18-x86_64-linux ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.18-x86_64-darwin ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.18-arm64-darwin ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.18-aarch64-linux ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.17-aarch64-linux ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.17-x86_64-darwin ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.17-x86_64-linux ./lib/cipherstash-pg/text_encoder.rb
cipherstash-pg-1.0.0.beta.17-arm64-darwin ./lib/cipherstash-pg/text_encoder.rb