rom-http icon indicating copy to clipboard operation
rom-http copied to clipboard

Possibility to set up config in relation's definition

Open firstsano opened this issue 6 years ago • 2 comments

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...

firstsano avatar Dec 01 '18 14:12 firstsano

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.

solnic avatar Dec 03 '18 08:12 solnic

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.

firstsano avatar Dec 03 '18 16:12 firstsano