Class: AttrAccessible2StrongParams

Inherits:
Object
  • Object
show all
Defined in:
lib/attr_accessible2strong_params.rb,
lib/attr_accessible2strong_params/version.rb

Defined Under Namespace

Classes: Converter

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Class Method Details

.convert(file_or_dir, no_rename = false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/attr_accessible2strong_params.rb', line 6

def self.convert(file_or_dir, no_rename = false)
  @files = []
  if file_or_dir.nil? or not File.exist?(file_or_dir)
    puts 'aa2sp [filename OR dirname]'
    return
  end
  if File.directory?(file_or_dir)
    Find.find("#{file_or_dir}/app/models/") do |path|
      next if path.end_with? '.rb.rb'
      @files << path if path.end_with? '.rb'
    end
  else
    @files << file_or_dir if File.exist? file_or_dir
  end
  @files.each do |filename|
    c = AttrAccessible2StrongParams::Converter.new
    next if c.read_attr_accessible(filename).blank?
    print(filename, ' found:', c.model_fields)
    c.remove_attr_accessible_from_model(filename, no_rename)
    c.write_controller_with_strong_params(nil, no_rename)
    puts
  end
end