Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior in calculation of default as option for nested collections #3

Open
emerson-h opened this issue Sep 24, 2014 · 0 comments · May be fixed by #4
Open

Unexpected behavior in calculation of default as option for nested collections #3

emerson-h opened this issue Sep 24, 2014 · 0 comments · May be fixed by #4

Comments

@emerson-h
Copy link

Specifically, when creating a perspective for a plain old ruby object, it invokes .base_class on the class of the first collection member.

Additionally, for namespaced classes, the default has an unexpected value when used to construct the Perspectives for the Collection. In many cases the behavior is counterintuitive and can result in an ArgumentError being raised by asset_valid_params!.

For instance given these classes and perspectives:

module Foo
  class FooClass
    def bazes
      [
        Foo::Bar::Baz.new,
        Foo::Bar::Baz.new
      ]
    end
  end
  module Bar
    class Baz 
       ...
    end
  end
end

# Foo Perspective
module Foo
  module FooClasses
    class Show
      param :foo

      nested_collection '/foo/bar/baz/show',
        collection: proc { foo.bazes },
        property: :bazes
    end
  end
end

# Baz Perspective
module Foo
  module Bar
    module Baz
      class Show
        param :baz

        ....
      end
    end
  end
end

Trying to render the foo/foo_classes/show perspective will raise an ArgumentError because it does not instantiate the baz show perspective with a :baz param. The default param key in this case is :foo::bar::baz.

It seems more advantageous to default to the demodulized class name, and to only use the base_class method if it is available so that nested collections can be used with POROs.

I've created a fix that does this in my fork of the project. When you have a chance can you take a look, and add your thoughts about what this behavior should be.

Thanks!

@emerson-h emerson-h changed the title Unexpected behavior in calculation of default as option Unexpected behavior in calculation of default as option for nested collections Sep 24, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant