Skip to content

Document creating an adapter more thoroughly #41

@thedrow

Description

@thedrow

I have the following adapter code:

require 'rom'
require 'rom-http'

module ROM
  module RestfullClientAdapter
    class Dataset < ROM::HTTP::Dataset
      default_request_handler -> (dataset) do
        puts "begin request"
      end

      default_response_handler -> (response, dataset) do
        puts "end request"
      end

      def response_transformer(response)

      end
    end

    class Gateway < ROM::HTTP::Gateway; end

    class Relation < ROM::HTTP::Relation
      adapter :restfull_client

    end

    module Commands
      class Create < ROM::HTTP::Commands::Create
        adapter :restfull_client
      end

      class Update < ROM::HTTP::Commands::Update
        adapter :restfull_client
      end

      class Delete < ROM::HTTP::Commands::Delete
        adapter :restfull_client
      end
    end
  end
end

ROM.register_adapter(:restfull_client, ROM::RestfullClientAdapter)

and I'm getting to following exception:

KeyError: key not found: :base
/Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rom-2.0.0/lib/rom/plugins/relation/view.rb:35:in `fetch'
/Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rom-2.0.0/lib/rom/plugins/relation/view.rb:35:in `attributes'
/Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rom-repository-0.3.1/lib/rom/repository/relation_proxy.rb:212:in `method_missing'
/Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rom-repository-0.3.1/lib/rom/repository/relation_proxy.rb:132:in `to_ast'
/Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rom-repository-0.3.1/lib/rom/repository.rb:203:in `compile_command'
/Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rom-repository-0.3.1/lib/rom/repository.rb:138:in `block in command'
/Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/concurrent-ruby-1.0.2/lib/concurrent/map.rb:133:in `block in fetch_or_store'
/Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/concurrent-ruby-1.0.2/lib/concurrent/map.rb:122:in `fetch'
/Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/concurrent-ruby-1.0.2/lib/concurrent/map.rb:132:in `fetch_or_store'
/Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rom-repository-0.3.1/lib/rom/repository.rb:137:in `command'
/Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rom-repository-0.3.1/lib/rom/repository/class_interface.rb:116:in `block in define_command_method'
./spec/rom_restful_client_adapter_spec.rb:15:in `block (2 levels) in <top (required)>'
-e:1:in `load'
-e:1:in `<main>'

After digging a bit it seems I need to set the option base to be an instance but I'm not sure of which class.
So I did:

    class Relation < ROM::HTTP::Relation
      adapter :restfull_client

      option :base, self
    end

and now I get:

/Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rom-support-2.0.0/lib/rom/support/options.rb:49:in `initialize': undefined method `fetch' for ROM::RestfullClientAdapter::Relation:Class (NoMethodError)
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rom-support-2.0.0/lib/rom/support/options.rb:164:in `new'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rom-support-2.0.0/lib/rom/support/options.rb:164:in `option'
    from /Volumes/fiverr_dev/restfull-client/lib/rom_adapter.rb:25:in `<class:Relation>'
    from /Volumes/fiverr_dev/restfull-client/lib/rom_adapter.rb:22:in `<module:RestfullClientAdapter>'
    from /Volumes/fiverr_dev/restfull-client/lib/rom_adapter.rb:5:in `<module:ROM>'
    from /Volumes/fiverr_dev/restfull-client/lib/rom_adapter.rb:4:in `<top (required)>'
    from /Volumes/fiverr_dev/restfull-client/spec/support/models.rb:2:in `require'
    from /Volumes/fiverr_dev/restfull-client/spec/support/models.rb:2:in `<top (required)>'
    from /Volumes/fiverr_dev/restfull-client/spec/spec_helper.rb:6:in `load'
    from /Volumes/fiverr_dev/restfull-client/spec/spec_helper.rb:6:in `block in <top (required)>'
    from /Volumes/fiverr_dev/restfull-client/spec/spec_helper.rb:6:in `each'
    from /Volumes/fiverr_dev/restfull-client/spec/spec_helper.rb:6:in `<top (required)>'
    from /Users/omer.katz/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/omer.katz/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/configuration.rb:1394:in `block in requires='
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/configuration.rb:1394:in `each'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/configuration.rb:1394:in `requires='
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/configuration_options.rb:112:in `block in process_options_into'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/configuration_options.rb:111:in `each'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/configuration_options.rb:111:in `process_options_into'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/configuration_options.rb:21:in `configure'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:99:in `setup'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:86:in `run'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/invocations.rb:23:in `call'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:69:in `run'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:45:in `invoke'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/exe/rspec:4:in `<top (required)>'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/bin/rspec:23:in `load'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/bin/rspec:23:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'

After adding fetch to the Relation class I get:

/Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rom-2.0.0/lib/rom/relation/class_interface.rb:129:in `rescue in []': Failed to find relation class for coercer adapter. Make sure ROM setup was started and the adapter identifier is correct. (ROM::AdapterNotPresentError)
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rom-2.0.0/lib/rom/relation/class_interface.rb:127:in `[]'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rom-support-2.0.0/lib/rom/support/options.rb:51:in `initialize'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rom-support-2.0.0/lib/rom/support/options.rb:164:in `new'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rom-support-2.0.0/lib/rom/support/options.rb:164:in `option'
    from /Volumes/fiverr_dev/restfull-client/lib/rom_adapter.rb:29:in `<class:Relation>'
    from /Volumes/fiverr_dev/restfull-client/lib/rom_adapter.rb:22:in `<module:RestfullClientAdapter>'
    from /Volumes/fiverr_dev/restfull-client/lib/rom_adapter.rb:5:in `<module:ROM>'
    from /Volumes/fiverr_dev/restfull-client/lib/rom_adapter.rb:4:in `<top (required)>'
    from /Volumes/fiverr_dev/restfull-client/spec/support/models.rb:2:in `require'
    from /Volumes/fiverr_dev/restfull-client/spec/support/models.rb:2:in `<top (required)>'
    from /Volumes/fiverr_dev/restfull-client/spec/spec_helper.rb:6:in `load'
    from /Volumes/fiverr_dev/restfull-client/spec/spec_helper.rb:6:in `block in <top (required)>'
    from /Volumes/fiverr_dev/restfull-client/spec/spec_helper.rb:6:in `each'
    from /Volumes/fiverr_dev/restfull-client/spec/spec_helper.rb:6:in `<top (required)>'
    from /Users/omer.katz/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/omer.katz/.rvm/rubies/ruby-2.2.2/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/configuration.rb:1394:in `block in requires='
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/configuration.rb:1394:in `each'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/configuration.rb:1394:in `requires='
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/configuration_options.rb:112:in `block in process_options_into'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/configuration_options.rb:111:in `each'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/configuration_options.rb:111:in `process_options_into'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/configuration_options.rb:21:in `configure'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:99:in `setup'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:86:in `run'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/invocations.rb:23:in `call'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:69:in `run'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/lib/rspec/core/runner.rb:45:in `invoke'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/gems/rspec-core-3.5.2/exe/rspec:4:in `<top (required)>'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/bin/rspec:23:in `load'
    from /Users/omer.katz/.rvm/gems/ruby-2.2.2@restfull_client/bin/rspec:23:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'

It's really not clear what I should be doing.
Can you guys please help me and also document the process?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions