Skip to content

Unable to set site outside of Base class #215

Closed
@dmbrooking

Description

@dmbrooking

So I have something similiar to the example code. If I do this:

module MyApi
  # this is an "abstract" base class that
  class Base < JsonApiClient::Resource
    # set the api base url in an abstract base class
    self.site = "http://example.com/"
  end
end

everything works.

If I try and set the site var outside of MyApi::Base, it fails.

If I have

MyApi::Base.site = "http://example.com/"
module MyApi
  # this is an "abstract" base class that
  class Base < JsonApiClient::Resource
  end
end

the connection fails with the error of

     # Errno::ECONNREFUSED:
     #   Connection refused - connect(2) for nil port 80

Using pry, if I get the following:

[1] pry(#<RSpec::ExampleGroups::RecordType>)> MyApi::Base.site
=> "http://example.com/"
[2] pry(#<RSpec::ExampleGroups::RecordType>)> cd MyApi::Base
[3] pry(MyApi::Base):1> self.site
=> "http://example.com/"
[4] pry(MyApi::Base):1> site
=> "http://example.com/"

which is what I expect. I'm not sure what's happening...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions