ruby-grape / ruby-grape/grape-entity

Can i have multiple call inside single module

Open
#267 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
729
Forks
154
PR merge metrics
No merged PRs in 30d

Description

I want to have multiple classes inside grape entity file, this is the folder structure app/api/proj/api/v2/entities/committee.rb

module PROJ::API::V2::Entities
class Committee < Grape::Entity
expose :id

expose :name, :full_name, :email, :tag, :parent_id

expose :country do |entity, option|
entity.parent.name if entity.parent.present?
end

include Urls

private
def self.namespace_path
"committees"
end
end

class CommitteeWithSubcommittees < CommitteeBase
# include ProfilePhoto
expose :suboffices, with: 'PROJ::API::V2::Entities::CommitteeBase'
end
and inside the grape api

present @committees, with: PROJ::API::V2::Entities::Committee
is working. but if i present with

present @committees, with: PROJ::API::V2::Entities::CommitteeList
it is not working. But it works when i move it to a new file named committee_list.rb inside entities

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with app/api/proj/api/v2/entities/committee.rb and compare the defined Committee and CommitteeWithSubcommittees classes with the Grape present calls. Check the corresponding standalone committee_list.rb file and determine whether the intended entity name is CommitteeWithSubcommittees or CommitteeList. Done means the intended entity can be referenced from the single file without breaking presentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.