Skip to content

Commit

Permalink
support not mention the controller file name while writing back.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Guo committed Oct 4, 2014
1 parent 858990e commit 0714c3e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/attr_accessible2strong_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def self.convert(file_or_dir)
@files << path if path.end_with? '.rb'
end
else
@files << file_or_dir
@files << file_or_dir if File.exist? file_or_dir
end
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/attr_accessible2strong_params/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

class AttrAccessible2StrongParams::Converter
def read_attr_accessible(filename)
@model_file_name = filename
root_node, comments, buffer = parse_file_with_comments(filename)
aa_nodes = root_node.each_node(:send).select {|n| n.children[1] == :attr_accessible}
aa_fields = []
Expand All @@ -21,7 +22,8 @@ def remove_attr_accessible_from_model(filename, no_rename = false)
write_file_with_comments(filename, no_aa_node, comments, no_rename)
end

def write_controller_with_strong_params(filename, no_rename = false)
def write_controller_with_strong_params(filename = nil, no_rename = false)
filename = "#{File.dirname @model_file_name}/../controllers/#{@model_class_name.pluralize.underscore}_controller.rb" if filename.nil?
root_node, comments, buffer = parse_file_with_comments(filename)
sp_src_buffer = Parser::Source::Buffer.new('(string)')
sp_src_buffer.source = ModifyControllerRewriter.new(@model_class_name, @model_fields).rewrite(buffer,root_node)
Expand Down
2 changes: 1 addition & 1 deletion test/test_attr_accessible2strong_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ def test_remove_attr_accessible_from_model
def test_write_controller_src
c = AttrAccessible2StrongParams::Converter.new
c.read_attr_accessible('test/railsapp/app/models/material_transfer_issue.rb')
assert_equal 0, c.write_controller_with_strong_params('test/railsapp/app/controllers/material_transfer_issues_controller.rb', true)
assert_equal 0, c.write_controller_with_strong_params(nil, true)
end
end

0 comments on commit 0714c3e

Please sign in to comment.