Search code examples
rubyread-eval-print-looppryhanami

method-call in REPL returns weirdly nothing


I am recently trying to implement a mixin, which accesses a configuration-object based on the namespace of the point of execution. The following snippet from my mixin extracts that namespace-part and caches it in an instance-variable of the mixin-target:

    if @asset_uri_helpers_config_ref.nil? == true then # initialize configuration-cache
      application_name = self.class.name.split('::').first # extract app-name from class-name
      @asset_uri_helpers_config_ref = Object.const_get("#{application_name}::Application").configuration
    end
    binding.pry # start the repl-session here

After that i'm accessing the method @asset_uri_helpers_config_ref.assets() which originally is defined at <<namespace>>::Application.configuration.assets(). The addicted unit-tests (where i stubbed the configuration-object) run (of course) fine.

The subsequent integration tests fail and to find out what happens, i added the above outlined repl-invokation. Now, when investigating the return values i get the following output:

[1] pry(#<Collaboration::Views::Assets::UseUriHelpers>)> @asset_uri_helpers_config_ref.assets
=> 
[2] pry(#<Collaboration::Views::Assets::UseUriHelpers>)> defined? @asset_uri_helpers_config_ref.assets()
=> "method"
[3] pry(#<Collaboration::Views::Assets::UseUriHelpers>)> @asset_uri_helpers_config_ref.assets.pretty_inspect
=> [[:object_id, [], nil],
 [:pretty_print,
  [#<Pry::ColorPrinter:0x007fb47b971058
    @buffer=[],
...
[4] pry(#<Collaboration::Views::Assets::UseUriHelpers>)> @asset_uri_helpers_config_ref.assets.nil?
=> [[:object_id, [], nil],
 [:pretty_print,
  [#<Pry::ColorPrinter:0x007fb47b971058
    @buffer=[],
...

I have no clue what i am getting here - any attempt to check the return value agains f.e. nil? (command #4) fails. It somehow looks like an exception - but then an Error should be thrown even when i call .assets() directly (command #1).

Can anybody explain what i am getting here?

The output above come from a BasicObject

I am accessing the wrong Class and therefore get a BasicObject-derivation back which appends all method_missing-invokations into an Array.


Solution

  • @florian You picked the wrong configuration.

    You should refer to Web::Assets.configuration.prefix, instead of Web::Application.configuration.assets.

    The latter is a proxy that "accumulates" all the commands and then apply them to the target configuration.