lib/alba/one.rb in alba-0.8.0 vs lib/alba/one.rb in alba-0.9.0
- old
+ new
@@ -1,26 +1,12 @@
+require 'alba/association'
+
module Alba
# Representing one association
- class One
- def initialize(name:, resource: nil, &block)
- @name = name
- @resource = resource
- @block = block
- raise ArgumentError, 'resource or block is required' if @resource.nil? && @block.nil?
- end
-
+ class One < Association
def to_hash(target)
object = target.public_send(@name)
@resource ||= resource_class
@resource.new(object).to_hash
- end
-
- private
-
- def resource_class
- klass = Class.new
- klass.include(::Alba::Resource)
- klass.class_exec(&@block)
- klass
end
end
end