Sha256: 52faffb29417800f4b21766826a749d936957e5f0efc070e0dfe05cd5090ea4e

Contents?: true

Size: 529 Bytes

Versions: 3

Compression:

Stored size: 529 Bytes

Contents

require 'alba/version'
require 'alba/resource'
require 'json'

# Core module
module Alba
  class Error < StandardError; end

  class << self
    attr_reader :backend
  end

  def self.backend=(backend)
    @backend = backend&.to_sym
  end

  def self.serialize(object)
    fallback = ->(resource) { resource.to_json }
    case backend
    when :oj
      begin
        require 'oj'
        ->(resource) { Oj.dump(resource) }
      rescue LoadError
        fallback
      end
    else
      fallback
    end.call(object)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
alba-0.3.0 lib/alba.rb
alba-0.2.0 lib/alba.rb
alba-0.1.0 lib/alba.rb