lib/rom/http/relation.rb in rom-http-0.6.0 vs lib/rom/http/relation.rb in rom-http-0.7.0

- old
+ new

@@ -1,8 +1,7 @@ require 'dry/core/cache' require 'rom/initializer' -require 'rom/plugins/relation/key_inference' require 'rom/http/transformer' module ROM module HTTP # HTTP-specific relation extensions @@ -12,27 +11,16 @@ extend ::ROM::Initializer include Enumerable adapter :http - use :key_inference - option :transformer, reader: true, default: proc { ::ROM::HTTP::Transformer } - forward :with_request_method, :with_path, :append_path, :with_options, - :with_params, :clear_params + forward :with_headers, :add_header, :with_options, + :with_base_path, :with_path, :append_path, + :with_request_method, :with_params, :add_params - - def initialize(*) - super - - raise( - SchemaNotDefinedError, - "You must define a schema for #{self.class.register_as} relation" - ) unless schema? - end - def primary_key attribute = schema.find(&:primary_key?) if attribute attribute.alias || attribute.name @@ -81,25 +69,25 @@ dataset.delete end private - def with_transformation(&block) - tuples = block.call + def with_transformation + tuples = yield transformed = with_schema_proc do |proc| transformer_proc[Array([tuples]).flatten(1).map(&proc.method(:call))] end tuples.kind_of?(Array) ? transformed : transformed.first end - def with_schema_proc(&block) + def with_schema_proc schema_proc = fetch_or_store(schema) do Types::Coercible::Hash.schema(schema.to_h) end - block.call(schema_proc) + yield(schema_proc) end def transformer_proc if mapped? transformer[:map_array, transformer[:rename_keys, mapping]]