Set site/user fields in ActiveResource

前端 未结 2 1513
小蘑菇
小蘑菇 2021-01-22 17:54

I am building a sinatra app that will use Highrise CRM gem to access Highrise data. This gem is based on ActiveResource class. I want to set site, user fields for every request.

相关标签:
2条回答
  • 2021-01-22 18:06

    I've been playing a lot with setting site option dynamically during runtime and the only solution I have found which will not lead to race condition.

    class Runner
      def self.new(site)
        Class.new(ActiveResource::Base) do
          self.site = site
          self.element_name = 'runner'
    
          # your methods here
        end.new
      end
    end
    
    0 讨论(0)
  • 2021-01-22 18:06

    While defining method with define_method you can specify its arguments passing them as arguments to the block and not to define_method itself. So you can define setter method like that:

    define_method("#{attr}=") do |val|
      Thread.current["active_resource.#{attr}"] = val
    end
    
    0 讨论(0)
提交回复
热议问题