File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -139,9 +139,19 @@ def gets_number
139139 end
140140 end
141141
142+ def gets_snake_case
143+ loop do
144+ print '> '
145+ val = $stdin. gets . chomp
146+ return val if val . lower_snake_case?
147+
148+ puts 'Value has to be lower_snake_caase. Please try again.'
149+ end
150+ end
151+
142152 def fetch_args_interactive
143153 puts 'Choose your controller name (use lower_snake_case)'
144- @args [ :name ] = gets_non_empty
154+ @args [ :name ] = gets_snake_case
145155
146156 puts 'Choose your parent controller'
147157 # passing parent as a string if we already have an object is hacky
Original file line number Diff line number Diff line change @@ -16,6 +16,10 @@ def to_camel
1616 self
1717 end
1818
19+ def lower_snake_case?
20+ match? ( /^[a-z_]+$/ )
21+ end
22+
1923 def to_snake
2024 return self if match? ( /_/ )
2125
Original file line number Diff line number Diff line change 2020 expect ( 'hello_world' . to_camel ) . to eq ( 'HelloWorld' )
2121 expect ( 'hello' . to_camel ) . to eq ( 'Hello' )
2222 end
23+ it 'Should detect snake case' do
24+ expect ( 'HelloWorld' . lower_snake_case? ) . to eq ( false )
25+ expect ( 'helloW' . lower_snake_case? ) . to eq ( false )
26+ expect ( 'HellO__' . lower_snake_case? ) . to eq ( false )
27+ expect ( 'hello' . lower_snake_case? ) . to eq ( true )
28+ expect ( 'hello_world' . lower_snake_case? ) . to eq ( true )
29+ end
2330 end
2431end
You can’t perform that action at this time.
0 commit comments