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

Adding :prefix option for has_enumeration_for #26

Merged
merged 2 commits into from Jul 31, 2012
Merged

Adding :prefix option for has_enumeration_for #26

merged 2 commits into from Jul 31, 2012

Conversation

lerrua
Copy link
Contributor

@lerrua lerrua commented Jul 26, 2012

Hi Cássio!

First let me apologize for my bad English and also because this is my first pull request, hope to do it right. XD

My name is Igor Leroy and I work with Cairo and Sobrinho in Nohup and always use your enumerate_it in our projects. =)

However there was a situation where I needed to create a feature to generate prefixes, helpers, I'll show you an example:

  has_enumeration_for :ordered, :with => MileageControlGroup, :create_helpers => true
  has_enumeration_for :grouped, :with => MileageControlGroup, :create_helpers => true

The objects grouped and ordered use the same Enumeration, but I need helpers unique to each object, for example ordered_name? and grouped_name? for my views on some reports that we do.

Now just do

has_enumeration_for :grouped, :with => MileageControlGroup, :create_helpers => true, :prefix => true

and solved my problem.

I hope you accept my Pull Request and thank you for this gem. ;)

@cassiomarques
Copy link
Collaborator

Hello Igor,

Nice idea!

Just some thoughts about it: I think the code would be more readable if the :prefix option had a more "descriptive" name. What does it prefixes? It's not clear by just reading the code, someone that's using the gem would need to go read the docs to understand the meaning of :prefix.

What if we did something similar to what ActiveModel validations do? For instance, to create a :length validation that makes an object be invalid if the attribute has more than 30 characters, you could do:

validates :foo, :length => {:maximum => 30}

The same idea could be used for the :create_helpers option:

has_enumeration_for :foo, :create_helpers => true # like we do today

OR...

has_enumeration_for :foo, :create_helpers => {:prefix => true}

Thoughs?

@caironoleto
Copy link
Contributor

@cassiomarques It's a good idea :D

@MarceloCajueiro
Copy link

I agree with this syntax:

has_enumeration_for :foo, :create_helpers => {:prefix => true}

@lerrua
Copy link
Contributor Author

lerrua commented Jul 27, 2012

@cassiomarques nice!

@cassiomarques
Copy link
Collaborator

@lerrua Very nice! Looks pretty solid for me. I will merge it now and during the weekend will try to write some documentation about this changes and release a new gem version.

Thanks a lot!

cassiomarques added a commit that referenced this pull request Jul 31, 2012
Adding the ability to pass a hash to the :create_helpers option, so the created helper methods can have an optional prefix.
@cassiomarques cassiomarques merged commit 1061f75 into lucascaton:master Jul 31, 2012
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 this pull request may close these issues.

None yet

4 participants