Skip to content

Instantly share code, notes, and snippets.

@amiel
Created July 27, 2012 18:40
Show Gist options
  • Save amiel/3189699 to your computer and use it in GitHub Desktop.
Save amiel/3189699 to your computer and use it in GitHub Desktop.
Looking for feedback on a change to ActiveModel

Hello, I'm looking for feedback on a possible pull-request to rails.

Here's the idea: right now any time an ActiveModel::Name is needed, it is accessed through model.class.model_name.

In other words, currently, it's something like this:

  # Somewhere in rails
  model.class.model_name


class MyModel
  def self.model_name
    ActiveModel::Name.new(self)
  end
end

And I'd like it to be like this:

  # Somewhere in rails
  model.model_name


class MyModel
  def self.model_name
    ActiveModel::Name.new(self)
  end

  delegate :model_name, to: :'self.class'
end

Here's a gist of what inspired me to try going this direction: https://gist.github.com/3096204

So, here's where I started: https://github.com/amiel/rails/commit/a64e5b4ccf9e851b06cd2eb64d824a9c2043c6e7

My initial questions are:

  1. Do you think this is a good idea? Also, I'm surprised this hasn't been done already, have I missed a rejected pull request?
  2. How should the instance method model_name be added to ActiveModel classes? The class method model_name is provided by extending ActiveModel::Naming. Is it appropriate to use the extended hook in ActiveModel::Naming to either include another module or use define_method?
  3. What are some arguments for or against the change? I'm mostly looking for arguments for the change to include in the pull request description, but I'm also curious what the arguments against would be.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment