lib/alba.rb in alba-0.4.0 vs lib/alba.rb in alba-0.5.0
- old
+ new
@@ -1,21 +1,32 @@
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
- end
- def self.backend=(backend)
- @backend = backend&.to_sym
- end
+ def backend=(backend)
+ @backend = backend&.to_sym
+ end
- def self.serialize(object)
- Serializers::DefaultSerializer.new(object).serialize
+ 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