lib/synvert/snippets/rails/convert_dynamic_finders.rb in synvert-0.0.16 vs lib/synvert/snippets/rails/convert_dynamic_finders.rb in synvert-0.0.17
- old
+ new
@@ -21,21 +21,21 @@
end
end
within_files '**/*.rb' do
# find_all_by_... => where(...)
- with_node type: 'send', message: /find_all_by_/ do
+ with_node type: 'send', message: /^find_all_by_/ do
hash_params = dynamic_finder_to_hash("find_all_by_")
if node.receiver
replace_with "{{receiver}}.where(#{hash_params})"
else
replace_with "where(#{hash_params})"
end
end
# find_by_... => where(...).first
- with_node type: 'send', message: /find_by_/ do
+ with_node type: 'send', message: /^find_by_/ do
if :find_by_id == node.message
if node.receiver
replace_with "{{receiver}}.find({{arguments}})"
else
replace_with "find({{arguments}}"
@@ -49,40 +49,40 @@
end
end
end
# find_last_by_... => where(...).last
- with_node type: 'send', message: /find_last_by_/ do
+ with_node type: 'send', message: /^find_last_by_/ do
hash_params = dynamic_finder_to_hash("find_last_by_")
if node.receiver
replace_with "{{receiver}}.where(#{hash_params}).last"
else
replace_with "where(#{hash_params}).last"
end
end
# scoped_by_... => where(...)
- with_node type: 'send', message: /scoped_by_/ do
+ with_node type: 'send', message: /^scoped_by_/ do
hash_params = dynamic_finder_to_hash("scoped_by_")
if node.receiver
replace_with "{{receiver}}.where(#{hash_params})"
else
replace_with "where(#{hash_params})"
end
end
# find_or_initialize_by_... => find_or_initialize_by(...)
- with_node type: 'send', message: /find_or_initialize_by_/ do
+ with_node type: 'send', message: /^find_or_initialize_by_/ do
hash_params = dynamic_finder_to_hash("find_or_initialize_by_")
if node.receiver
replace_with "{{receiver}}.find_or_initialize_by(#{hash_params})"
else
replace_with "find_or_initialize_by(#{hash_params})"
end
end
# find_or_create_by_... => find_or_create_by(...)
- with_node type: 'send', message: /find_or_create_by_/ do
+ with_node type: 'send', message: /^find_or_create_by_/ do
hash_params = dynamic_finder_to_hash("find_or_create_by_")
if node.receiver
replace_with "{{receiver}}.find_or_create_by(#{hash_params})"
else
replace_with "find_or_create_by(#{hash_params})"