'Rails helper doesn't have access to base class method
I've got helper which I'm including inside Create
service class. This Create
service inherits from Base class and I'm including ::Imports::HashFieldsBuilder
to have access to its size_fields
method - like below:
Base class:
# frozen_string_literal: true
module Products
class Base
def with_retry(limit: 3, wait: 2, &block)
block.call
rescue Imports::Client::BadGatewayError => e
attempt ||= 0
attempt += 1
sleep(wait) and retry if attempt < limit
raise e
end
def client
@client ||= Imports::Client.new
end
end
end
Create class:
# frozen_string_literal: true
module Products
class Create < Base
include ::Imports::HashFieldsBuilder
def initialize(product:)
@product = product
end
def call
ActiveRecord::Base.transaction do
size_fields(product)
end
end
end
end
Helper which is included inside Create service:
module Imports::HashFieldsBuilder
extend self
def size_fields(product)
with_retry { client.product_size_specs(product_id: product['_id']) }
end
end
This code produces me an error:
NoMethodError: undefined method `with_retry' for Imports::HashFieldsBuilder:Module
Which means that ::Imports::HashFieldsBuilder
doesn't have access Base
class methods: with_retry
and client
. But why? I have already included this helper to the Client
class, which inherits from the Base class.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|