Module: RDBr::Web::BinaryValueHelpers

Included in:
Helpers
Defined in:
lib/rdbr/web/binary_value_helpers.rb

Constant Summary collapse

BINARY_TYPES =
%i[binary blob bytea image longblob mediumblob tinyblob varbinary].freeze

Instance Method Summary collapse

Instance Method Details

#binary_column?(column) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
# File 'lib/rdbr/web/binary_value_helpers.rb', line 8

def binary_column?(column)
  type = column.logical_type.to_s.to_sym
  BINARY_TYPES.include?(type) || column.sql_type.to_s.match?(/(?:binary|blob|bytea)/i)
end

#deferred_binary_value?(column, value) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/rdbr/web/binary_value_helpers.rb', line 13

def deferred_binary_value?(column, value)
  binary_column?(column) || encoded_binary_value?(value)
end

#render_binary_value(value) ⇒ Object



17
18
19
20
21
# File 'lib/rdbr/web/binary_value_helpers.rb', line 17

def render_binary_value(value)
  payload, bytes = binary_payload(value)
  summary = binary_summary(bytes)
  render_deferred_value(payload, qualifier: 'binary', summary: summary)
end