Sha256: 617f4d31813b9c7fff5c908eb751ca193a28fab80f18c88a971f4087f77360a7

Contents?: true

Size: 668 Bytes

Versions: 1

Compression:

Stored size: 668 Bytes

Contents

require 'alba/version'
require 'alba/serializers/default_serializer'
require 'alba/serializer'
require 'alba/resource'
require 'alba/resources/default_resource'

# Core module
module Alba
  class Error < StandardError; end

  class << self
    attr_reader :backend

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

    def serialize(object, with: nil, &block)
      raise ArgumentError, 'Block required' unless block

      resource_class.class_eval(&block)
      resource = resource_class.new(object)
      resource.serialize(with: with)
    end

    private

    def resource_class
      ::Alba::Resources::DefaultResource.clone
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alba-0.5.0 lib/alba.rb