class RailsZen::WriteToMigration
Public Instance Methods
append_to_line(line)
click to toggle source
# File lib/rails_zen/write_to_files/write_to_migration.rb, line 15 def append_to_line(line) gsub_file file_name, /t.#{attr_type}.+#{name}.*$/ do |match| match = line end end
file_name()
click to toggle source
# File lib/rails_zen/write_to_files/write_to_migration.rb, line 21 def file_name Dir.glob("db/migrate/*create_#{@model_name.pluralize}.rb")[0] # need to use pluralize here end
write!()
click to toggle source
# File lib/rails_zen/write_to_files/write_to_migration.rb, line 6 def write! if @validator line = send(@validator) append_to_line(line) end if scope_attr.any? inject_into_file file_name, "t.index #{scope_attr.to_s}\n", before: "t.timestamps" end end
Private Instance Methods
validates_presence_of()
click to toggle source
# File lib/rails_zen/write_to_files/write_to_migration.rb, line 27 def validates_presence_of "t.#{attr_type} :#{name}, required: true, null: false" end
validates_uniqueness_of()
click to toggle source
# File lib/rails_zen/write_to_files/write_to_migration.rb, line 30 def validates_uniqueness_of "t.#{attr_type} :#{name}, required: true, null: false, index: true" end
validates_uniqueness_scoped_to()
click to toggle source
# File lib/rails_zen/write_to_files/write_to_migration.rb, line 33 def validates_uniqueness_scoped_to "t.#{attr_type} :#{name}, required: true, null: false, index: true" end