Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

simple refactoring for future improvement

  • Loading branch information...
commit b053cb950d23b0ffc6d1be9b132cc327c34b5f8c 1 parent a267986
@kucaahbe authored
Showing with 5 additions and 6 deletions.
  1. +5 −6 lib/annotated/models.rb
View
11 lib/annotated/models.rb
@@ -69,8 +69,6 @@ def annotation
other_column_attrs = []
other_column_attrs << NOT_NULL unless column.null
other_column_attrs << DEFAULT % column.default if column.default
- # https://github.com/rails/rails/blob/965f6f22aaee3b669d185b2ea2e125abaf458a63/activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb#L227
- # todo SQL type at the end of table?
annotation_table << sprintf(
%Q|# %s %-#{column_with_maximum_name_length+1}s:%-16s%s|,
@@ -128,13 +126,15 @@ def annotate! options = {}
# TODO remove old annotation
#gsub_file annotator.path, annotator.remove_regexp
puts_message "Annotating #{annotator.model}"
- gsub_file annotator.path, annotator.add_regexp, annotator.annotation
+ content = File.read(annotator.path).gsub(annotator.add_regexp, annotator.annotation)
+ write_file annotator.path, content
end
end
def denotate!
annotators.each do |annotator|
- gsub_file annotator.path, annotator.remove_regexp, ''
+ content = File.read(annotator.path).gsub(annotator.remove_regexp, '')
+ write_file annotator.path, content
end
end
@@ -158,8 +158,7 @@ def annotators
protected
- def gsub_file destination, regexp, *args, &block
- content = File.read(destination).gsub(regexp, *args, &block)
+ def write_file destination, content
File.open(destination, 'wb') { |file| file.write(content) }
end

0 comments on commit b053cb9

Please sign in to comment.
Something went wrong with that request. Please try again.