rom-rb / rom-http

Abstract HTTP adapter for ROM
https://rom-rb.org
MIT License
73 stars 18 forks source link

Possibility to set up config in relation's definition #37

Open firstsano opened 5 years ago

firstsano commented 5 years ago

Is there a way to set default params for current relation? I want to be able not to include these kind of lines

.with_base_path('users')
.add_params(expand: 'account,account_details')

everywhere in current relation...

solnic commented 5 years ago

This is not supported yet, you can just handle it on your own for now by storing a pre-configured relation somewhere and use that at run-time. We could add a feature that would make this simpler.

firstsano commented 5 years ago

Got it. So for now I think I'll use it as:

  class UsersRelation < ::ROM::Relation[:http]
    # schema definition goes here
    def by_id(id)
      base.with_path(id.to_s)
    end

    def all
      base.to_a
    end

    private

    def base
      with_base_path('users')
        .add_params(expand: 'account,account_details')
    end
  end

I'll try to help, maybe with PR, when I get more time.