Delegate is actually an alias
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Comienza en JSONAPI::Resource y en el manejo de delegación de la opción attributes; después, compara su comportamiento con los ejemplos de delegación de Ruby y Rails incluidos en el issue. Se considera terminado cuando la opción delegate reenvía el método al objeto delegado tal como se describe, o cuando su comportamiento similar a un alias está claramente documentado.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
When working with the gem and trying to look at how to hide underlying models I came across the delegate option which is available on a resource.
Using this option I expected the same result as with the definitions provided in both ruby and rails. When I delegate a method to something, it calls the method being delegated on that something.
An example:
class Bar
attr_accessor :name
def initialize
@name = "Test"
end
end
class Foo
extend Forwardable
attr_accessor :bar
def initialize
@bar = Bar.new
end
def_delegator :@bar, :name
end
Foo.new.name # => "Test"
foo = Foo.new
foo.bar.name = "Demo"
foo.name # => "Demo"
This passes the delegate method along to the object @bar.
Now looking at the way it is defined in JSONAPI::Resource we have the following option:
class Bar
attr_accessor :name
def initialize
@name = "Test"
end
end
class Foo
attr_accessor :bar
def initialize
@bar = Bar.new
end
end
class FooResource < JSONAPI::Resource
attributes :name, delegate: :bar
end
FooResource.new(Foo.new, {}).name # => <Bar:0x007fd288c69708 @name="Test">
As you can see when calling name on the resource it gives me back the object Bar instead of calling the method name on the Bar object. This is more in line with how alias works instead of how delegate works.
It might be an idea to make this clearer in the documentation to prevent any confusion, and it maybe an idea in the future to modify this behaviour to be the same as how ruby and rails handle this.
- Lenguaje dominante
- Ruby
- Estrellas
- 2.3k
- Forks
- 546
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de JSONAPI-Resources/jsonapi-resources
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
-
ArgumentError with Rails 8.1 Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 50/100
JSONAPI-Resources/jsonapi-resources#1488 · 1 comentario ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
JSONAPI-Resources/jsonapi-resources#1479 · 2 comentarios ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
JSONAPI-Resources/jsonapi-resources#1477 · 3 comentarios · 1 reacción ·
-
Fields filtering with include Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
Todos los issues de JSONAPI-Resources/jsonapi-resources
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Please Drop ruby 3.2 support Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
googleapis/google-api-ruby-client#28001 · 5 reacciones ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100