shrinerb / shrine

File Attachment toolkit for Ruby applications

Home Page:https://shrinerb.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Entity defines `:name` method with args

tmtrademarked opened this issue · comments

Brief Description

Attacher.get doesn't accept arguments, but the entity definition defines a :name method with args.

Expected behavior

The entity plugin seems to define a method that aliases attacher.get which takes in arguments. So I'd expect to be able to call icon(:foo), for example. It seems like Shrine should either pass the arguments down the chain, or not claim to be able to accept them.

Actual behavior

This call results in an errror:

[2] pry(main)> t.icon('foo')
ArgumentError: wrong number of arguments (given 1, expected 0)
from .rbenv/versions/3.0.0/lib/ruby/gems/3.0.0/gems/shrine-3.4.0/lib/shrine/attacher.rb:240:in `get'

Simplest self-contained example code to demonstrate issue

class MyClass < ApplicationRecord # has the column icon_data
  include Shrine::Attachment[:icon]
end

obj = MyClass.new
obj.icon(:foo)

System configuration

Ruby version: 3.0.0

Shrine version: 3.4.0

Hmm, that's a tough one. The entity plugin passes down arguments from the model method to Attacher#get because the derivatives plugin overrides Attacher#get with the ability to accept arguments. Technically, the derivatives plugin could probably override the model method to forward arguments, so that the entity plugin can define it with no arguments. I agree that getting an ArgumentError down the chain can be misleading, so I'll look into this.