@Everton -- cool!  Yeah, I think it's a fairly common problem.

I out started with a similar syntax to yours, but I found that writing out 
"default: ..." every time got cumbersome. Since it's a command line 
generator, the terser the syntax can be the better. In the end I liked a = 
character the best to indicate the default.  Of the alternatives, : was 
more complicated to parse, > evoked the ":default =>" syntax nicely but did 
strange things with the output, so = seemed like a nice, terse, clear 
option.  

Here's the PR, feel free to comment and make suggestions: 
https://github.com/rails/rails/pull/18075

Thanks! 

Alex

On Sunday, December 14, 2014 6:31:22 PM UTC-6, EMoreth wrote:
>
> Hi, I actually have this on my projects, I still need to make it public, 
> but I was trying to make it more stable first.
>
> The main idea was to be able to add anything inside the brackets, so you 
> could include anything valid as options. The main problem is to use spaces 
> or quotes.
>
> rails g migration AddGearsToBicycles gears:integer[default:3
> ,limit:10,null:false]
>
> In my version, I also create the models (when models are created) using 
> the validations for each parameter, when applicable.
>
> Ill try to create an public repo for that in a day or two. 
>
> On Tue, Dec 2, 2014 at 7:34 PM, Alex Soble <aso...@gmail.com <javascript:>
> > wrote:
>>
>> Good point Mohamed -- thanks for noticing that! 
>>
>> And thanks for the encouragement Rodrigo and Austin.  
>>
>> On Tuesday, December 2, 2014 8:58:01 AM UTC-6, Mohamed Wael Khobalatte 
>> wrote:
>>>
>>> Sounds good. Keep in mind that you could potentially be dealing with 
>>> dynamic values (such as Date, Time, and co) and also binary data, ltrees, 
>>> and so on. Ideally you want to cover all these types, which is prehaps why 
>>> this was not done in the first place. 
>>>
>>> On Tue, Dec 2, 2014 at 8:22 AM, Austin Story <lonnie...@gmail.com> 
>>> wrote:
>>>
>>>> I like it too.  Looks like it would be an easy change as well.  
>>>>
>>>> On Monday, December 1, 2014 4:18:47 PM UTC-6, Alex Soble wrote:
>>>>>
>>>>> Hi Rails core team,
>>>>>
>>>>> I've been mulling over an idea for a bit of new syntax, want to hear 
>>>>> what you think about it. 
>>>>>
>>>>> Two of the most common things I do as a developer when generating a 
>>>>> new migration are (1) add defaults to help avoid nil errors and (2) add 
>>>>> indices to attributes like foreign keys for performance. The migration 
>>>>> generator comes with nice syntax that makes adding indices easy: 
>>>>>
>>>>> $ bin/rails generate migration AddPartNumberToProducts part_number:
>>>>> string:index
>>>>>
>>>>> (from http://guides.rubyonrails.org/migrations.html#
>>>>> creating-a-standalone-migration)
>>>>>
>>>>> But there's no corresponding syntax for adding defaults. You generate 
>>>>> the migration, find the generated file, add defaults by hand and then run 
>>>>> the migration.  What about a way to add defaults to new migrations from 
>>>>> the 
>>>>> command line?  Could look like this:
>>>>>
>>>>> rails g migration AddGearsToBicycles gears:integer[default:3]
>>>>>
>>>>> Or in a new model:
>>>>>
>>>>> rails g model Bicycle mileage:integer[default:0] gears:integer[default
>>>>> :3]
>>>>>
>>>>> Improvements or suggestions on the proposed syntax?  Any feedback 
>>>>> would be much appreciated!  Thanks everyone.
>>>>>
>>>>  -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Ruby on Rails: Core" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to rubyonrails-co...@googlegroups.com.
>>>> To post to this group, send email to rubyonra...@googlegroups.com.
>>>> Visit this group at http://groups.google.com/group/rubyonrails-core.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>>
>>>
>>>
>>> -- 
>>> Mohamed Wael Khobalatte
>>>
>>>   -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Ruby on Rails: Core" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to rubyonrails-co...@googlegroups.com <javascript:>.
>> To post to this group, send email to rubyonra...@googlegroups.com 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/rubyonrails-core.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
> -- 
> Att,
> Everton
> http://www.evertonmoreth.com.br
>  

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to