Skip to content

Commit

Permalink
Extract to new remove_attr_accessible_from_model methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric-Guo committed Oct 3, 2014
1 parent dc341c8 commit 27bf79d
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/attr_accessible2strong_params/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ def read_attr_accessible(filename)
@model_class_name = m.parent.parent.children[0].children[1]
aa_fields <<= m.each_node(:sym).collect {|n| n.children[0]}
end
rewriter = RemoveAttrAccessibleRewriter.new
no_aa_src = rewriter.rewrite(buffer,root_node)

no_aa_src_buffer = Parser::Source::Buffer.new('(string)')
no_aa_src_buffer.source = no_aa_src
no_aa_node = Parser::CurrentRuby.new(Astrolabe::Builder.new).parse(no_aa_src_buffer)
write_file_with_comments(filename, no_aa_node, comments)
write_file_with_comments(filename, remove_attr_accessible_from_model(buffer, root_node), comments)
@model_fields = aa_fields.flatten
end

Expand All @@ -44,4 +38,10 @@ def write_file_with_comments(filename, root_node, comments)
end
File.rename(temp_path, filename)
end

def remove_attr_accessible_from_model(buffer, root_node)
no_aa_src_buffer = Parser::Source::Buffer.new('(string)')
no_aa_src_buffer.source = RemoveAttrAccessibleRewriter.new.rewrite(buffer,root_node)
Parser::CurrentRuby.new(Astrolabe::Builder.new).parse(no_aa_src_buffer)
end
end

0 comments on commit 27bf79d

Please sign in to comment.