1
module API
  module V1
    module Entities
      class A < Grape::Entity
        expose :k 
        expose :l
        expose :status 

        def status
         'HI'
        end
      end
    end
  end
end

module API
  module V101
    module Entities
      class A < V1::Entities::A
        expose :status

        def status
         'BYE'
        end
      end
    end
  end
end

In this case with grape-entity, when I am calling the V101 it is calling the status function of V1 instead of the V101 at first. This means - first it is executing the status function of v1 and then v101. This code perfectly works with the grape-entity version = 0.4.8 where it only calls the function of v101 when I call with v101. After version >= 0.5 this code does not behave as before. Ami I missing something? Thank you!

Related Configuration
rails: 5.2
grape: 1.6.2
  • It sounds like the behavior of `expose` changed when it determines the "target method". The past behavior may have looked up the "target" at runtime and now that lookup is done when your class is loaded -- which would mean that v101 #status method isn't defined yet. – BM5k Jun 06 '22 at 16:15
  • Maybe something in https://github.com/ruby-grape/grape-entity/compare/v0.4.8..v0.5.0 would explain the behavior change better – BM5k Jun 06 '22 at 16:18
  • I tried to understand what made the difference and noticed `lib/grape_entity/entity.rb` there are some significance change on self of **Entity** class from 0.4.8 to 0.5.0. But could not understand what was causing this issue and how to handle this scenario! – Syed Hassan Jun 06 '22 at 16:27

0 Answers0