erase
# File lib/generators/auth_code_refactor.rb, line 6 def clear_user_relations erase_in_user(has_roles_through_assignments) erase_in_user(has_roles) erase_in_user(has_role_assignments) end
# File lib/generators/auth_code_refactor.rb, line 12 def erase_in_user(txt) file = File.new(model_file('user')) return if !(file.read =~ /#{txt}/) gsub_file model_file('user'), /#{Regexp.escape(txt + "\n")}/, '' end
refactor code
# File lib/generators/auth_code_refactor.rb, line 40 def has_role_assignments 'has_many :role_assignments' end
# File lib/generators/auth_code_refactor.rb, line 48 def has_roles 'has_many :roles' end
# File lib/generators/auth_code_refactor.rb, line 44 def has_roles_through_assignments 'has_many :roles, :through => :role_assignments' end
# File lib/generators/auth_code_refactor.rb, line 26 def insert_user_relation(relation) file = File.new(model_file('user')) return if (file.read =~ /#{relation}/) gsub_file model_file('user'), /class User < ActiveRecord::Base/ do |match| match << "\n #{relation}" end end
# File lib/generators/auth_code_refactor.rb, line 34 def remove_user_relation(relation) erase_in_user(relation) end
# File lib/generators/auth_code_refactor.rb, line 61 def role_assignment_file_content %q{ class RoleAssignment < ActiveRecord::Base belongs_to :user belongs_to :role end } end
# File lib/generators/auth_code_refactor.rb, line 52 def role_file_content %q{ class Role < ActiveRecord::Base has_many :role_assignments has_many :users, :through => :role_assignments end } end
insert
# File lib/generators/auth_code_refactor.rb, line 20 def write_model_file(name, content) File.open(model_file(name), 'w+') do |f| f.write(content) end end