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

Get attribute name within normalizer #74

Open
tanraya opened this issue Nov 21, 2015 · 1 comment
Open

Get attribute name within normalizer #74

tanraya opened this issue Nov 21, 2015 · 1 comment
Labels

Comments

@tanraya
Copy link

tanraya commented Nov 21, 2015

I would like to create a normalizer with auto-truncation feature, so I need to know the current limit of a table field. To determine the length of the field I need to know the name of the attribute.

Here's what I want:

  config.normalizers[:auto_truncate] = lambda do |value, options|
    column = options[:model].column_for_attribute(options[:attribute_name])

    if value.is_a?(String) && column.limit
      value.mb_chars.limit(column.limit)
    else
      value
    end
  end

I looked into the source and found nothing relative to the topic. What if I add :attribute_name and :model keys into options hash and send PR?

@mdeering
Copy link
Owner

Yes. I can see value in knowing the attribute and even having access to instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants